Vue.js 表格数据操作:选中行获取、删除
怎么获取选中的行,获取数据js的数据,如何从静态列表中删除内容:要获取选中的行,可以使用@selection-change事件,然后在对应的方法中获取选中的行数据。以下是一个示例:
methods: {
PlanleSelectionChange(selection) {
// selection为选中的行数据数组
console.log(selection);
}
}
要删除静态列表中的数据,可以在对应的删除方法中使用splice()函数来删除指定位置的数据。以下是一个示例:
methods: {
DelSelection(selection) {
// selection为选中的行数据数组
selection.forEach(item => {
const index = this.PlantableData.indexOf(item);
if (index > -1) {
this.PlantableData.splice(index, 1); // 删除选中的行数据
}
});
}
}
注意,splice()函数会直接修改原数组,所以在Vue中直接修改数组会触发响应式更新,界面也会相应地更新。
原文地址: https://www.cveoy.top/t/topic/pE2B 著作权归作者所有。请勿转载和采集!