的关于你提供的代码的问题,你可以通过在按钮上设置一个自定属性来分别按钮。

对于第一个按钮,你可以添加一个名为“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() {
  // &#x83B7;&#x53D6;&#x6309;&#x94AE;&#x7C7B;&#x578B;
  const buttonType = event.target.getAttribute('buttonType');

  if (buttonType === 'add') {
    // &#x6267;&#x884C;&#x65B0;&#x589E;&#x64CD;&#x4F5C;
  } else if (buttonType === 'modify') {
    // &#x6267;&#x884C;&#x4FEE;&#x6539;&#x64CD;&#x4F5C;
  } else {
    // &#x5176;&#x5B83;&#x64CD;&#x4F5C;
  }
}

希望这些可以帮助到你!

Element Plus 按钮区分:新增、修改、添加 - 如何获取按钮类型进行判断

原文地址: https://www.cveoy.top/t/topic/qgOe 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录