点击删除数据时,一般要进行二次确认,避免手误删除的可能。
handleDelete(scope) {
this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
const index = this.tableData.findIndex(item => {
return item.name === scope.row.name
})
if (index !== -1) {
this.tableData.splice(index, 1)
this.allData = [...this.tableData] //遗漏影响查询操作
}
this.$message({
type: 'success',
message: '删除成功!'
});
}).catch(() => {
this.$message({
type: 'info',
message: '已取消删除'
});
});
}
}
备注:
调用$confirm
方法即可打开消息提示,它模拟了系统的 confirm;
type
字段表明消息类型,可以为success
,error
,info
和warning
,无效的设置将会被忽略;
bug集:
1、问题:删除后,点击查询,删除的数据还显示在表格内。
解决:将动态表格拷贝给全部表格:this.allData = [...this.tableData]