要获取按钮的名称,可以使用事件对象(event)的target属性来获取点击的按钮元素,然后通过按钮元素的innerText属性获取按钮的文本内容。修改代码如下:

<el-button type="success" size="small" link @click="openFormB(scope.row)" buttonType="tj">添加++</el-button>
<el-button type="success" plain @click="openFormB()" buttonType="xz">新增</el-button>
methods: {
  openFormB(event) {
    const buttonType = event.target.innerText;
    if (buttonType === '新增') {
      console.log('xxxxx是新增嗷呜xxxxx');
    } else if (buttonType === '添加') {
      console.log('xxxxx是添加嗷呜xxxxx');
    }
  }
}

这样就可以根据按钮的名称进行判断了

elementPLUS中新增添加这俩按钮一个在列表上方一个在行内操作栏里面。怎么给按钮取名字获取到是哪个按钮进行if判断 el-button type=success size=small link click=openFormBscoperow buttonType=tj添加++el-button el-button type=success plain click=openFormB butt

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

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