el-table表格某列添加icon图标和可编辑输入框
<el-table
key="one"
style="border-collapse: collapse;min-height: 65vh;"
:data="tableData"
:key="randomKey"
@cell-click="editName"
>
<el-table-column prop="sky_target" label="当天目标" align="center">
<template slot="header" slot-scope="scope">
当天目标<i class="el-icon-setting" />
</template>
<template slot-scope="scope">
<el-input
v-if="scope.row[scope.column.property + 'isShow']"
:ref="scope.column.property"
v-model="scope.row.sky_target"
@blur="alterData(scope.row, scope.column)"
></el-input>
<span v-else>{{ scope.row.sky_target }}</span>
</template>
</el-table-column>
</el-table>
data:{
isShow: true,
randomKey: Math.random(),
}
methods:{
editName(row, column) {
row[column.property + 'isShow'] = true
// refreshTable是table数据改动时,刷新table的
this.refreshTable()
this.$nextTick(() => {
this.$refs[column.property] && this.$refs[column.property].focus()
})
},
alterData(row, column) {
row[column.property + 'isShow'] = false
this.refreshTable()
},
refreshTable() {
this.randomKey = Math.random()
},
}