Element-UI table 单元格数据可编辑



<el-table v-loading="loading" :data="tabels" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="表名" prop="name" width="120" align="center"/>
<el-table-column label="表解释" width="200" align="center">
<template slot-scope="scope">
<el-input
placeholder="请输入内容"
v-model="scope.row.remark"
:disabled="scope.row.update == 0?true:false"
style="width:75%"
></el-input>
<i
class="el-icon-edit-outline"
style="margin-left:10px"
v-if="scope.row.update == 0"
@click="scope.row.update = 1"
></i>
<i
class="el-icon-check"
style="margin-left:10px"
v-else
@click="updateRemark(scope.row)"
></i>
</template>
</el-table-column>
</el-table-column>
<script>
import { getTableList,updateRemark } from "@/api/table";
export default {
name: "Role",
dicts: ['sys_normal_disable'],
data() {
return {
tabels: [],
loading: true,
};
},
created() {
this.getList();
},
methods: {
updateRemark(rows){
console.log(rows)
updateRemark({id:rows.id,remark:rows.remark}).then(
res=>{
console.log(res)
rows.update = 0
}
);
},
handleClick(rows){
console.log(rows)
},
getList(){
getTableList().then(
res=>{
res.rows.forEach(item =>{
item.update = 0
})
this.tabels = res.rows
this.loading = false
}
);
},
handleSelectionChange(e){
console.log(e)
}
}
}