Element Plus 按钮区分:新增、修改、添加 - 如何获取按钮类型进行判断
的关于你提供的代码的问题,你可以通过在按钮上设置一个自定属性来分别按钮。
对于第一个按钮,你可以添加一个名为“buttonType”的属性并设置为“add”:
<el-button type="success" plain buttonType="add" @click="openFormB()"><i-ep-plus />新增</el-button>
对于第二个按钮,你可以添加一个名为“buttonType”的属性并设置为“modify”:
<el-button type="primary" size="small" link buttonType="modify" @click="openFormB(scope.row)">修改</el-button>
对于第三个按钮,你可以添加一个名为“buttonType”的属性并设置为“add”:
<el-button type="success" size="small" link buttonType="add" @click="openFormB(scope.row)">添加</el-button>
然后,在事件处理方法中,你可以获取按钮的“buttonType”属性并进行对应的判断:
openFormB() {
// 获取按钮类型
const buttonType = event.target.getAttribute('buttonType');
if (buttonType === 'add') {
// 执行新增操作
} else if (buttonType === 'modify') {
// 执行修改操作
} else {
// 其它操作
}
}
希望这些可以帮助到你!
原文地址: https://www.cveoy.top/t/topic/qgOe 著作权归作者所有。请勿转载和采集!