编辑的时候先把数据存起来
// 编辑
edit(key) {
const newData = [...this.data]
const target = newData.filter(item => key === item.key)[0]
this.editingKey = key
if (target) {
// 把target 存入editingLine中
this.editingLine = { ...target }
target.editable = true
this.data = newData
}
},
点击取消editingLin赋给this.data[i]
// 取消
cancel(key) {
for (let i = 0; i < this.data.length; i++) {
if (key === this.data[i].key) {
this.data[i] = this.editingLine
this.editingKey = ''
break
}
}
const newData = [...this.data]
const target = newData.filter(item => key === item.key)[0]
this.editingKey = ''
if (target) {
delete target.editable
this.data = newData
}
},