Vue在el-table中使用el-popover遇到的坑
el-table表格中使用el-popover打开和关闭失效的问题及解决过程
在 element-ui 中 el-table 中使用Popover弹框
<el-table-column>
<template slot-scope="scope">
<el-popover placement="bottom" title="更多" width="100" trigger="click" :ref="`popover-${scope.$index}`">
<el-button type="primary" size="mini" @click="handleConfirm(scope)">确定</el-button>
<el-button type="text" size="small" slot="reference">更多</el-button>
</el-popover>
</template>
</el-table-column>
这里ref使用变量的形式,因为是多个循环的el-popover
这里需要点击确定来关闭el-popover窗口,发现如下代码不生效
handleConfirm(scope) {
scope._self.$refs[`popover-${scope.$index}`].doClose()
scope._self.$refs[`popover-${scope.$index}`].showPopper = false
}
发现vue 不能检测到ref的值变化 不能触发视图更新,原因是表格中添加lazy 懒加载
通过如下代码解决
handleConfirm() {
document.body.click() // 模拟点击页面其它部分关掉弹层,因为该页面列表使用懒加载导致doClose无效
}

在Element-UI的el-table组件中使用el-popover时,遇到了点击关闭失效的问题,原因在于表格的懒加载特性。解决方法是通过模拟点击页面其他区域来关闭弹层,例如使用`document.body.click()`。这个技巧对于处理因懒加载导致的弹层控制失效问题具有一定的参考价值。

被折叠的 条评论
为什么被折叠?



