由于开发需求,需要在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>
在开发过程中,遇到一个关于Element-ui的el-table组件的问题,即在表格中使用popover显示详细信息。当表格翻页后,popover无法正常显示。通过分析发现是组件复用导致的,通过在el-popover上添加v-if判断条件,只有当有详细数据时才渲染,成功解决了这个问题。

109

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



