el-select的el-option添加操作按钮插槽后实现勾选与按钮操作分离

 这里我在el-option的选项文字后面添加了两个svg按钮(编辑和删除):如图

当我们点击el-option时无法区分是勾选el-option还是点击了el-option选项文字后面的按钮,其实只要在后面的编辑和删除的操作按钮的click事件上面添加.native.stop即可阻止事件冒泡,实现勾选与操作分离------点击操作按钮区域外为勾选,点击操作按钮即操作

见以下代码

                      <el-option v-for="item in dataResourceOptions" :key="item.value" :label="item.label" :value="item.value" >
                        <template #default>
                          <div class="flex items-center justify-between">
                            <div class="flex items-center gap-5">
                              <div class="flex items-center w-18">
                                <app-svg-icon icon-name="check" class="w-18 h-18"></app-svg-icon>
                              </div>
                              <span>{{ item.label }}</span>
                            </div>
                            <div class="flex items-center gap-5">
                              <div class="w-25 h-25 flex items-center pl-5 option-operation-button" @click.native.stop="handleFieldItemClick(item,'编辑')"><app-svg-icon icon-name="pencil" class="w-16 h-16"></app-svg-icon></div>
                              <div  class="w-25 h-25 flex items-center pl-5 option-operation-button" @click.native.stop="handleFieldItemClick(item,'删除')"><app-svg-icon icon-name="x-close" class="w-16 h-16"></app-svg-icon></div>
                            </div>
                          </div>
                        </template>
                      </el-option>

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值