记工作过程中遇到的el-table表格中使用el-popover打开和关闭失效的问题及解决过程

在这里插
首先,上图是需要实现的效果,在表格中点击测试按钮弹出popover框

坑来了:

当我想要通过点击测试按钮来让popover框显示的时候我试图这样做:

// An highlighted block
//html部分
          <el-popover
            placement="top-start"
            trigger="manual"
            :ref="scope.$index"
            v-model="visible[scope.$index]">
 
            <el-button @click="saveSqlTestInterface(scope.$index, scope.row)"
            size="mini"
            icon="el-icon-stopwatch"
            type="primary" slot="reference"
                     >测试
            </el-button>
          </el-popover>
// An highlighted block
//js部分
saveSqlTestInterface (index,data) {
	this.visible[index] = true
}

结果发现devtools中的值变了,但是并没有体现到页面上

经过查看大佬们分享的经历和心得之后得到结论与解决办法

结论:vue 不能检测到数组变化 不能触发视图更新,所以直接赋值没有引起popover的响应

解决办法:

1.splice方法可以触发视图更新

// An highlighted block
//js部分
saveSqlTestInterface (index,data) {
	 this.visible.splice(index, 1, true);
}

2.通过ref获取元素之后发现,元素上面已经内置打开的方法(关闭同理)

// An highlighted block
//js部分
saveSqlTestInterface (index,data) {
	 this.$refs[index].doShow()
	 //this.$refs[index].doClose() //关闭popover
}
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值