<template>
<div>
<el-button @click="test">test</el-button>
<el-table :data="tableData" :row-class-name = "tableRowClassName" @cell-click="cellClick" style="width: 100%">
<el-table-column label="日期" width="180">
<template slot-scope="scope">
<el-input v-model="scope.row.date" @blur="handleInputBlur" v-if="scope.$index ===rowIndex && cellClickLabel == '日期'" clearable></el-input>
<span v-else>{{scope.row.date}}</span>
</template>
</el-table-column>
<el-table-column label="姓名" width="180">
<template slot-scope="scope">
<el-input v-model="scope.row.name" @blur="handleInputBlur" v-if="scope.$index ===rowIndex && cellClickLabel == '姓名'" clearable></el-input>
<span v-else>{{scope.row.name}}</span>
</template>
</el-table-column>
<el-table-column label="地址">
<template slot-scope="scope">
<span>{{scope.row.address}}</span>
</template>
</el-table-column>
</el-table>
</div>
</template>
数据
rowIndex:null,
cellClickLabel:"",
tableData: [
{
date: "2016-05-02",
name: "王小虎",
address: "上海市普陀区金沙江路 1518 弄",
},
{
date: "2016-05-04",
name: "王小虎",
address: "上海市普陀区金沙江路 1517 弄",
},
{
date: "2016-05-01",
name: "王小虎",
address: "上海市普陀区金沙江路 1519 弄",
},
{
date: "2016-05-03",
name: "王小虎",
address: "上海市普陀区金沙江路 1516 弄",
}
],
methods: {
test(){
console.log(this.tableData)
},
tableRowClassName({ row, rowIndex }) {
// 把每一行的索引放进row
row.index = rowIndex
},
// 添加明细原因 row 当前行 column 当前列
cellClick(row, column, cell, event) {
console.log("点击行")
this.rowIndex = row.index
this.cellClickLabel = column.label
},
//input框失去焦点事件
handleInputBlur(row, event, column){ //当 input 失去焦点 时,input 切换为 span,并且让下方 表格消失(注意,与点击表格事件的执行顺序)
console.log("失去焦点")
this.rowIndex = ""
this.cellClickLabel = ''
},
handleChange() {
console.log("change")
this.rowIndex = ""
this.cellClickLabel = ''
}
},
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有