<template slot-scope="scope">
<el-button
size="mini"
type="danger"
@click="handleDelete(scope.$index, scope.row)"
>
删除
</el-button>
</template>
handleDelete(index, row) {
// console.log(index, row);
api
.deleteItemById({
id: row.id,
})
.then((res) => {
this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
})
.then(() => {
if (res.data.status === 200) {
this.$message({
type: "success",
message: "删除成功!",
});
//视图重绘
this.http(1);
} else {
this.$message({
type: "error",
message: "删除失败!",
});
}
})
.catch(() => {
this.$message({
type: "info",
message: "已取消删除",
});
});
})
.catch((error) => {
console.log(error);
});
},
老师,这个视频里面从8分50秒开始的部分:视频中的删除功能引用了element组件库中的MessageBox弹窗提示,上面是视频中讲课老师编写的代码。但是我发现按照这样顺序写下来的话并没有起到 在删除数据前多做一次判断的作用,不管点击确定还是取消,后台数据其实都已经删除了。