el-table 封装
2020-12-31 本文已影响0人
海豚先生的博客
// 使用
<Tables
:tableData="tableData"
:propsLabelList="propsLabelList"
:showOperation="false"
:selection="false"
></Tables>
propsLabelList: [
["appName", "应用名称"],
["createTime", "创建时间"],
["editTime", "修改时间"]
]
// table.vue
<template>
<div>
<el-table
ref="multipleTable"
:data="tableData"
style="width: 100%"
:border="true"
:stripe="true"
@selection-change="handleSelectionChange"
>
<template v-if="selection">
<el-table-column
type="selection"
align="center"
width="55"
:fixed="freezeCol"
></el-table-column>
</template>
<el-table-column
type="index"
label="序号"
align="center"
width="55"
:fixed="freezeCol"
></el-table-column>
<template v-for="(item, i) in propsLabelList">
<el-table-column
show-overflow-tooltip
:key="i"
:prop="item[0]"
:label="item[1]"
align="center"
:min-width="item[1].length * 15 + 40"
></el-table-column>
</template>
<el-table-column
:fixed="freezeOperationLast"
v-if="showOperation"
align="center"
label="操作"
width="80"
>
<template slot-scope="scope">
<a
style="color:#46a0fc;cursor: pointer;"
@click="edit(scope.row[rowidKey])"
>编辑</a
>
</template>
</el-table-column>
</el-table>
</div>
</template>
<script>
export default {
props: {
selection: {
type: Boolean,
default: true
},
propsLabelList: {
type: Array,
default: []
},
tableData: {
type: Array,
default: []
},
rowidKey: {
type: String,
default: "id"
},
showOperation: {
type: Boolean,
default: true
},
freezeCol: {
type: [Boolean, String],
default: false
}
},
data() {
return {};
},
methods: {
edit(id) {
this.$emit("edit", id);
},
handleSelectionChange(val) {
console.log(val);
this.$emit("selectedList", val);
}
},
computed: {
freezeOperationLast() {
return this.freezeCol ? "right" : false;
}
}
};
</script>
<style></style>