首先在element-ui中的el-table下的el-table-column中引入插槽(相当于占位符)
<template slot-scope="scope">
<el-button size="mini" @click="handleEdit(scope.$index, scope.row)"
>编辑</el-button
>
<el-button
size="mini"
type="danger"
@click="handleDelete(scope.$index, scope.row)"
>删除</el-button
>
</template>
handleDelete(index, item) {
this.$confirm("你确定要删除吗,请三思,后果自负", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
})
.then(() => {
console.log("确定了,要删除");
})
.catch(() => {
console.log("放弃了");
});
},
此时,需要在main.js中注册组件
import {MessageBox} from 'element-ui';
// Vue.use(MessageBox);//与其他引用不同的是,这里“不能”加Vue.use(MessageBox),不然会出现问题,达不到想要的效果
Vue.prototype.$confirm = MessageBox.confirm;
使用Element-UI的Table组件实现编辑与删除功能
本文介绍了如何在Vue项目中利用Element-UI的Table组件结合插槽实现表格内的编辑和删除功能。通过在`el-table-column`内插入模板,定义`scope.row`来访问数据,并通过`$confirm`弹窗确认删除操作。关键步骤包括设置按钮触发事件和在main.js中注册MessageBox组件。
1327

被折叠的 条评论
为什么被折叠?



