Element-UI中el-table内嵌el-popover,在表格翻页后el-popover无法显示问题解决

由于开发需求,需要在el-table某一列增加popover弹窗,当用户点击按钮时,通过popover组件展示详细信息。参考Element-ui官网文档案例,得出代码如下

<el-table-column prop="sip,sip_location" label="源IP" width="150">
 <template slot-scope="scope">
    <div>
      {{ scope.row.sip }}
      <el-popover
        placement="right"
        width="500px"
        :visible="IPDetailsPop"
        popper-class="IPDetailsPopover"
      >
        <IPDetails ref="ipdetails" :info="info"/>
        <el-button
          type="text"
          icon="el-icon-search"
          slot="reference"
          @click="toggleIPDetailsDialog(scope.$index,'sip')"
        >
        </el-button>
      </el-popover>
    </div>
    <div v-for="item in scope.row.sip_location" :key="item">
       <div style="margin-bottom:2px">
        <el-tag effect="dark" color="#199fc7" size="mini" span="2" style="width:100%">{{
          item
        }}</el-tag>
      </div> 
    </div>
  </template>
</el-table-column>

在这里插入图片描述

具体实现细节无需关注,经过测试后表格第一页的popover组件能够正常显示,但是当翻到第二页时,点击详情按钮,函数能够被正常执行,数据也按照指定格式解析,但是popover组件无法显示。此时返回到第一页后,第一页的popover组件也无法显示了。
参考文章(https://juejin.cn/post/7200571354927939645#comment)中对组件复用问题的描述与解释,在el-popover添加v-if判断条件成功将问题解决,即当没有详细数据要展示的时候,不渲染popover组件。

<el-table-column prop="sip,sip_location" label="源IP" width="150">
 <template slot-scope="scope">
    <div>
      {{ scope.row.sip }}
      <el-popover
        placement="right"
        width="500px"
        :visible="IPDetailsPop"
        v-if="Object.keys(scope.row.sip_add).length>0"
        popper-class="IPDetailsPopover"
      >
        <IPDetails ref="ipdetails" :info="info"/>
        <el-button
          type="text"
          icon="el-icon-search"
          slot="reference"
          @click="toggleIPDetailsDialog(scope.$index,'sip')"
        >
        </el-button>
      </el-popover>
    </div>
    <div v-for="item in scope.row.sip_location" :key="item">
       <div style="margin-bottom:2px">
        <el-tag effect="dark" color="#199fc7" size="mini" span="2" style="width:100%">{{
          item
        }}</el-tag>
      </div> 
    </div>
  </template>
</el-table-column>
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值