自定义el-popover的开关【解决】

el-table需要增加一行可以单块编辑的部分需要弹窗一个下拉框选中后可以点击确认取消按钮

不是点不开就是关不上不然就是报错
一系列搜索后使用了ref的方法

给每个popover加上了ref(id唯一)(请注意使用ref后v-model这里就不要加了会互相影响)

点击开启关闭方法就使用popover提供的doShow()和doClose()方法

doShow我使用的时候点不开,换成了show()可以打开但是会报错(如下),然后在打开的方法里使用doShow()方法增加了document.body.click()一行成功打开,关闭也能正常使用

详细代码

  <el-table-column label="测试" width="230">
          <template slot-scope="scope">
            <el-popover
              placement="bottom"
              width="200"
              trigger="click"
              :ref="'pop' + scope.row.id"
            >
              <!-- v-model="typeVisible" -->//!!这里的typeVisible是一个遗漏点,第一次我把typeVisible跟ref都写上了导致一直点不开
             //内容省略
             //确定取消按钮
              <div style="text-align: right; margin: 0">
                <el-button
                  size="mini"
                  type="text"
                  @click="auditClose(scope.row.id)"
                  >取消</el-button
                >
                <el-button
                  type="primary"
                  size="mini"
                  @click="auditClose(scope.row.id)"
                  >确定</el-button
                >
              </div>
              <el-button
                slot="reference"
                type="text"
                size="medium"
                icon="el-icon-edit"
                class="text-button-edit"
                style="margin-left: 6px"
                @click="auditClick(scope.row.id)"
              />
            </el-popover>
          </template>
        </el-table-column>
  auditClick(id) {
      this.$refs[`pop${id}`].doShow();
//本来用doShow打不开然后换了this.$refs[`pop${id}`].click()this.$refs[`pop${id}`].show()都能打开,继续百度最后在下方加了document.body.click()以后不报错了
      document.body.click()
    },
    auditClose(id) {
      this.$refs[`pop${id}`].doClose();
    },

效果图

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值