问题描述
使用 ElementUI 的 el-popover 时,当存在多个 Popover 时或将 Popover 放入到表格中后,点击确定或者取消该 over 不消失的问题
如图所示:

<el-table-column align="center" label="操作" width="250" class-name="small-padding fixed-width">
  <template slot-scope="scope">
    <el-button  size="small" type="primary" @click="handleUpdate(scope.row)">编辑
    </el-button>
    <el-button  size="small" type="primary" @click="handleResult(scope.row)">查看结果
    </el-button>
    <el-popover ref="delpopover" placement="top" width="160" v-model="scope.row.delConfirmvisible">
      <p>确定删除吗?</p>
      <div style="text-align: right; margin: 0">
        <el-button size="mini" type="text" @click="scope.row.delConfirmvisible = false">取消</el-button>
        <el-button type="primary" size="mini" @click="handleDelete(scope.row)">确定</el-button>
      </div>
    </el-popover>
    <el-button size="small" type="danger" v-popover:delpopover >删除</el-button>
  </template>
</el-table-column>

点击取消的方法是

scope.row.delConfirmvisible = false

这个取消的方法是没有立即渲染的(即 popover 没有消失),这是因为vue 深入理解响应式原理,Vue 的官方文档其实也说明过,对于一个数组或者对象,直接去改变某个属性对应的值,虽然值是成功修改了,但是这种变动是无法反应到视图上的。
问题解决
于是,此时需要用数组的 splice 方法或者 vue 自带的 this.$set 方法。修改如下:
在这里插入图片描述

其中 scope.$index 是表格中每行数据的索引,delVisibles 是我新定义的一个数组,因为和 popover 绑定,其默认值是 false(不管 scope 表格数据有没有这个属性)

delVisibles: []

取消方法如下:

canclePopover(row, index){
  this.delVisibles.splice(index, 1, false);
  
  this.$set(this.delVisibles, index, false);
}

转载:https://www.dazhuanlan.com/rms/topics/1524382
如有侵权,请联系qq191221098

GitHub 加速计划 / eleme / element
15
2
下载
A Vue.js 2.0 UI Toolkit for Web
最近提交(Master分支:2 个月前 )
c345bb45 1 年前
a07f3a59 * Update transition.md * Update table.md * Update transition.md * Update table.md * Update transition.md * Update table.md * Update table.md * Update transition.md * Update popover.md 1 年前
Logo

AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。

更多推荐