項目場景:
表格實現(xiàn)編輯功能。在實際開發(fā)過程中,我們表格的表頭往往很多,有的還會發(fā)生變化,所以本文參考一位博主的代碼結(jié)合自己的項目進行了改編。
參考原文鏈接:vue element-ui實現(xiàn)table表格可編輯修改文章來源:http://www.zghlxwxcb.cn/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: "上海市普陀區(qū)金沙江路 1518 弄",
iseditor: false
},
{
date: "2016-05-04",
name: "王小虎",
address: "上海市普陀區(qū)金沙江路 1517 弄",
iseditor: false
},
{
date: "2016-05-01",
name: "王小虎",
address: "上海市普陀區(qū)金沙江路 1519 弄",
iseditor: false
},
{
date: "2016-05-03",
name: "王小虎",
address: "上海市普陀區(qū)金沙江路 1516 弄",
iseditor: false
}
]
}
},
methods:{
edit(row, index) {
row.iseditor = true;
},
save(row, index) {
row.iseditor = false;
}
}
}
</script>
<style scoped>
.st-table {
padding: 10px;
}
</style>
結(jié)果圖展示:
文章來源地址http://www.zghlxwxcb.cn/news/detail-538999.html
到了這里,關(guān)于element-ui中table表格標簽編輯功能的實現(xiàn)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!