element-ui popover 在表格中使用,不显示解决方案
代码如下
<template>
<el-table :data="tableData" border style="width: 100%">
<el-table-column label="日期" width="180">
<template scope="scope">
<el-icon name="time"></el-icon>
<span style="margin-left: 10px">{{ scope.row.date }}</span>
</template>
</el-table-column>
<el-table-column label="姓名" width="180">
<template scope="scope">
<el-popover trigger="hover" placement="top">
<p>姓名: {{ scope.row.name }}</p>
<p>住址: {{ scope.row.address }}</p>
<div slot="reference" class="name-wrapper">
<el-tag>{{ scope.row.name }}</el-tag>
</div>
</el-popover>
</template>
</el-table-column>
<el-table-column label="操作">
<template scope="scope">
<el-button size="small">编辑</el-button>
<el-popover trigger="click" :ref="`popover-${scope.$index}`" placement="top" width="100">
<p class="el-icon-warning">确定删除</p>
<div style="text-align: right; margin: 0">
<el-button
size="mini"
type="text"
@click="scope._self.$refs[`popover-${scope.$index}`].doClose()"
>取消</el-button>
<el-button
type="primary"
size="mini"
@click="scope._self.$refs[`popover-${scope.$index}`].doClose()"
>确定</el-button>
</div>
<el-button slot="reference" size="small" type="danger">删除</el-button>
</el-popover>
</template>
</el-table-column>
</el-table>
</template>
关键代码
<el-popover trigger="click" :ref="`popover-${scope.$index}`" placement="top" width="100">
<p class="el-icon-warning">确定删除</p>
<div style="text-align: right; margin: 0">
<el-button
size="mini"
type="text"
@click="scope._self.$refs[`popover-${scope.$index}`].doClose()"
>取消</el-button>
<el-button
type="primary"
size="mini"
@click="scope._self.$refs[`popover-${scope.$index}`].doClose()"
>确定</el-button>
</div>
<el-button slot="reference" size="small" type="danger">删除</el-button>
</el-popover>
–看到网上有一种方案是在data里面塞一个控制显示隐藏的字段,也能达到效果–