html
<el-table
ref="table"
:data="aqjyData"
border
style="width: 100%"
max-height="500"
@cell-click="rowstatus"
>
<el-table-column
label="序号"
width="150"
type="index"
/>
<el-table-column
label="建议"
width="auto"
>
<template slot-scope="scope">
<span
v-if="!scope.row.suggestFlag "
>
{{ scope.row.suggest }}
</span>
<el-input
v-if="scope.row.suggestFlag "
ref="input"
v-model="scope.row.suggest"
placeholder="请输入内容"
@blur="blur(scope.row,scope.column)"
/>
</template>
</el-table-column>
<el-table-column
label="操作"
width="120"
>
<template slot-scope="scope">
<el-button
type="text"
size="small"
@click.native.prevent="deleteRow(scope.$index, aqjyData)"
>
移除
</el-button>
</template>
</el-table-column>
</el-table>
js
methods:{
// 点击单元格切换单元格状态为输入框
rowstatus(row, column, cell, event) {
if (column.label === '建议') {
row.suggestFlag = true
//重新获取输入框的焦点
this.$nextTick(() => {
this.$refs.input.focus()
})
}
},
// 输入框失焦事件
blur(row, column) {
// 失焦时改变输入框的状态为表格
if (column.label === '建议') {
row.suggestFlag = false
}
},
}