1、
<el-table :data="tableData" @cell-click="cellClick"
:cell-class-name="getRowColumn">
<el-table-column prop="note" align="center" label="列1" >
<template slot-scope="scope">
<el-input v-if="scope.row.index==clickCellRowIndex && scope.column.index==clickCellColumnIndex" size="small" v-model="scope.row.note" @blur="inputBlur"
placeholder="请输入">
</el-input>
<span v-else>{{scope.row.note}}</span>
</template>
</el-table-column>
</el-table>
2、
data(){
return {
clickCellRowIndex:null,//用于判断点击是哪行
clickCellColumnIndex:null,//用于判断点击是哪列
}
}
3、
methods{
//输入框 失去焦点
inputBlur(index,row){
this.clickCellRowIndex = null
this.clickCellColumnIndex = null
},
//点击cell
cellClick(row,column,cell,event){
this.clickCellRowIndex = row.index
this.clickCellColumnIndex = column.index
},
//table初始化的时候给行和列 赋index
getRowColumn({row,column,rowIndex,columnIndex}){
row.index = rowIndex
column.index = columnIndex
},
}