el-popover在el-table中关闭不生效的解决方式

414 阅读1分钟

官网上的

image.png

为什么不生效:我们是表格渲染,有多条数据,相当于有多个el-popover组件同时绑定了一个值,造成了无法显示问题

解决方式:

//template
<el-popover placement="right" title="采购单价(不含运)" width="300" trigger="click"
 :ref="'popover-price-' + row.whId">
      <el-button type="primary"  @click="ppriceClose(row.whId)">确定</el-button>
</el-popover>
//methods
ppriceClose(id) {
  this.$refs[`popover-price-` + id][0].doClose()
},

point:给每个被渲染的组件加ref(id要不一样的)然后调用组件的doClose方法关闭

image.png