项目场景:
表格实现编辑功能。在实际开发过程中,我们表格的表头往往很多,有的还会发生变化,所以本文参考一位博主的代码结合自己的项目进行了改编。
参考原文链接:vue element-ui实现table表格可编辑修改文章来源:https://www.toymoban.com/news/detail-538999.html
代码展示
<template>
<div class="st-table">
<el-table :data="tableData" border style="width: 100%">
<el-table-column v-for="(item, index) in columns" :key="index" fixed :prop="item.prop" :label="item.label" width="180">
<template slot-scope="scope">
<input type="text" v-model="scope.row[item.prop]" v-show="scope.row.iseditor" />
<span v-show="!scope.row.iseditor">{{scope.row.date}}</span>
</template>
</el-table-column>
<el-table-column label="操作" width="180">
<template slot-scope="scope">
<el-button type="warning" @click="edit(scope.row, scope)">编辑</el-button>
<el-button type="danger" @click="save(scope.row)">保存</el-button>
</template>
</el-table-column>
</el-table>
</div>
</template>
<script>
export default {
name: 'HelloWorld',
data () {
return {
columns:[
{prop:'date',label:'时间',width:'150'},
{prop:'name',label:'姓名',width:'150'},
{prop:'address',label:'地址',width:'150'},
],
tableData: [
{
date: "2016-05-02",
name: "王小虎",
address: "上海市普陀区金沙江路 1518 弄",
iseditor: false
},
{
date: "2016-05-04",
name: "王小虎",
address: "上海市普陀区金沙江路 1517 弄",
iseditor: false
},
{
date: "2016-05-01",
name: "王小虎",
address: "上海市普陀区金沙江路 1519 弄",
iseditor: false
},
{
date: "2016-05-03",
name: "王小虎",
address: "上海市普陀区金沙江路 1516 弄",
iseditor: false
}
]
}
},
methods:{
edit(row, index) {
row.iseditor = true;
},
save(row, index) {
row.iseditor = false;
}
}
}
</script>
<style scoped>
.st-table {
padding: 10px;
}
</style>
结果图展示:
文章来源地址https://www.toymoban.com/news/detail-538999.html
到了这里,关于element-ui中table表格标签编辑功能的实现的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!