实现效果如图:
思路:在行数据中设置一个属性,用来区分当前行或者当前列是否在进行修改,使用v-if实现
<el-table
ref="multipleTable"
:data="tableData"
tooltip-effect="dark"
style="width: 100%"
@selection-change="handleSelectionChange"
:row-class-name="tableRowClassName"//此方法
v-loading="loading"
>
<el-table-column label="编号" width="120">
<template slot-scope="scope">
//判断
<div v-if="scope.row.index==tableCli">
<el-input v-model="scope.row.id"></el-input>
</div>
<span v-else>{{scope.row.id}}</span>
</template>
</el-table-column>
<el-table-column prop="title" label="编号"></el-table-column>
<el-table-column label="分类" prop="categoryId"></el-table-column>
<el-table-column label="操作">
<template slot-scope="scope">
<el-button type="text" @click="edit(scope.row, scope)">编辑</el-button>
</template>
</el-table-column>
</el-table>
<script>
export default {
name: "sourceSystem",
data() {
return {
//初始化
tableCli: -1,
tableData: [
{ id: 1, title: 2, categoryId: 3 },
{ id: 1, title: 2, categoryId: 3 },
{ id: 1, title: 2, categoryId: 3 }
],
};
},
methods: {
tableRowClassName({ row, rowIndex }) {
// 把每一行的索引放进row
row.index = rowIndex;
},
//
edit(row, index) {
//console.log(row, index);
this.tableCli = index.$index;
//console.log(this.tableCli);
},
},
//
mounted() {
};
</script>