渲染页面:
<template>
<div class="table">
<div class="crumbs">
<el-breadcrumb separator="/">
<el-breadcrumb-item><i class="el-icon-menu"></i> 表格</el-breadcrumb-item>
<el-breadcrumb-item>基础表格</el-breadcrumb-item>
</el-breadcrumb>
</div>
<div class="handle-box">
<el-button type="primary" icon="delete" class="handle-del mr10" @click="delAll">批量删除</el-button>
<el-select v-model="select_cate" placeholder="筛选医院" class="handle-select mr10">
<!--循环-->
<el-option key="1" label="广东省" value="广东省"></el-option>
<el-option key="2" label="湖南省" value="湖南省"></el-option>
</el-select>
<el-input v-model="select_word" placeholder="筛选关键词" class="handle-input mr10"></el-input>
<el-button type="primary" icon="search" @click="search">搜索</el-button>
</div>
<!---this.tableData的格式必须是数组套对象,prop中值为对象的键-->
<el-table border :data='this.tableData' style="width: 100%" ref="multipleTable" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55"></el-table-column>
<el-table-column prop="name" label = "姓名" sortable width="150">
</el-table-column>
<el-table-column prop="doc_job" label="职位" width="120">
</el-table-column>
<el-table-column prop="doc_hos" label="医院" >
</el-table-column>
<el-table-column prop="doc_tel" label="联系方式" >
</el-table-column>
<el-table-column label="操作" width="180">
<template slot-scope="scope">
<el-button size="small"
@click="handleEdit(scope.$index, scope.row)">编辑</el-button>
<el-button size="small" type="danger"
@click="handleDelete(scope.$index, scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<div class="pagination">
<el-pagination
@current-change ="handleCurrentChange"
layout="prev, pager, next"
:total="1">
</el-pagination>
</div>
</div>
</template>
<script>
export default {
data() {
return {
url: './static/vuetable.json',
tableData: [],
cur_page: 1,
multipleSelection: [],
select_cate: '',
select_word: '',
del_list: [],
is_search: false
}
},
created(){
this.getData();
},
methods: {
handleCurrentChange(val){
this.cur_page = val;
this.getData();
},
getData(){
let self = this;
// 通过NODE_ENV可以来设置环境变量(默认值为development)。 在terminal里面运行下面的命令就会有开发环境的调试数据,例如日志、mongodb的数据操作等等。一般我们通过检查这个值来分别对开发环境和生产环境下做不同的处理。可以在命令行中通过下面的方式设置这个值:
//linux & mac: export NODE_ENV=production windows:set NODE_ENV=production
if(process.env.NODE_ENV === 'development'){
//获取后台的数据路径
self.url = 'http://www.baidu.com';
};
let params = new URLSearchParams();//使用axios传参的转换对象
params.append('page', self.cur_page);//添加参数
self.$axios.post(self.url,params).then((res) => {
self.tableData = res.data;
})
},
search(){
//关键字查询;
this.is_search = true;
},
handleEdit(index, row) {
this.$message('编辑第'+(index+1)+'行');
},
handleDelete(index, row) {
this.$message.error('删除第'+(index+1)+'行');
},
delAll(){
const self = this,
length = self.multipleSelection.length;
let str = '';
self.del_list = self.del_list.concat(self.multipleSelection);
for (let i = 0; i < length; i++) {
str += self.multipleSelection[i].name + ' ';
}
self.$message.error('删除了'+str);
self.multipleSelection = [];
},
//获取侦听选中的对象
handleSelectionChange(val) {
this.multipleSelection = val;
}
}
}
</script>
<style scoped>
.handle-box{
margin-bottom: 20px;
}
.handle-select{
width: 120px;
}
.handle-input{
width: 300px;
display: inline-block;
}
</style>