使用vue和elementui写一段前端代码,第一行是一个下拉框,第二行是2个input,最后一行是一个可以使用树形数据的table表格并且有分页功能,表格需要自动占满剩余空间,同时页面使用flex布局
时间: 2023-05-23 11:00:58 浏览: 84
Vue + element-ui 【前端项目一】Table 表格并实现分页 2
以下是可以实现您的要求的前端代码示例:
```vue
<template>
<div class="container">
<div class="dropdown">
<el-select v-model="selectedOption" placeholder="请选择">
<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
</el-select>
</div>
<div class="input-group">
<el-input v-model="input1" placeholder="请输入"></el-input>
<el-input v-model="input2" placeholder="请输入"></el-input>
</div>
<div class="table">
<el-table :data="tableData" style="width: 100%" :row-class-name="tableRowClassName">
<el-table-column prop="name" label="姓名"></el-table-column>
<el-table-column prop="age" label="年龄"></el-table-column>
<el-table-column prop="address" label="地址"></el-table-column>
</el-table>
<el-pagination
class="pagination"
background
layout="prev, pager, next"
:page-size="pageSize"
:total="totalCount"
:current-page="currentPage"
@current-change="handlePageChange"
></el-pagination>
</div>
</div>
</template>
<script>
export default {
name: "MyComponent",
data() {
return {
options: [
{ label: "选项1", value: "option1" },
{ label: "选项2", value: "option2" },
{ label: "选项3", value: "option3" },
],
selectedOption: "",
input1: "",
input2: "",
tableData: [
{ name: "张三", age: 18, address: "北京市海淀区" },
{ name: "李四", age: 24, address: "上海市浦东区" },
{ name: "王五", age: 31, address: "广州市天河区" },
{ name: "赵六", age: 42, address: "深圳市南山区" },
],
currentPage: 1,
pageSize: 2,
totalCount: 4,
};
},
methods: {
tableRowClassName({ index }) {
return index % 2 === 0 ? "even-row" : "odd-row";
},
handlePageChange(page) {
this.currentPage = page;
// TODO: 根据分页信息查询数据
},
},
};
</script>
<style>
.container {
display: flex;
flex-direction: column;
height: 100%;
}
.dropdown {
margin-bottom: 16px;
}
.input-group {
display: flex;
}
.input-group > * {
flex: 1;
margin-right: 16px;
}
.table {
flex: 1;
overflow-y: auto;
margin-top: 16px;
}
.pagination {
margin-top: 16px;
display: flex;
justify-content: center;
}
</style>
```
请注意,上面的代码只是一个示例,您可以根据需要进行修改和扩展。如果您不熟悉 Vue 和 Element UI,建议先学习它们的基本用法。
阅读全文