table使用时候有时候会有下面界面
hover提示框,用element的el-popover可以显示该操作,但是会发现 取消操作的时候,el-popover不会自动消失,虽然失去焦点改框会自动消失,但是看起来对用户不是很友好
解决办法:
el-popover加个:value="visible[scope.$index]"来控制他的显示和隐藏
<template>
<el-table :data="tableData" style="width: 100%">
<el-table-column prop="date" label="日期" width="180"> </el-table-column>
<el-table-column prop="name" label="姓名" width="180"> </el-table-column>
<el-table-column prop="address" label="地址"> </el-table-column>
<el-table-column label="操作" min-width="90" align="center">
<template slot-scope="scope">
<el-popover :key="`${scope.$index}${new Date().valueOf()}del`" width="160" :value="visible[scope.$index]">
<p>确认删除此用户吗?</p>
<div style="text-align: right; margin: 0">
<el-button size="mini" type="text" @click="closePopover(scope.$index)">取消</el-button>
<el-button type="primary" size="mini" @click="deleteUser(scope.row, scope.$index)">确定</el-button>
</div>
<a :class="$style.edit" slot="reference">删除</a>
</el-popover>
<a :class="$style.dottedline">|</a>
<el-popover
:key="`${scope.$index}${new Date().valueOf()}reset`"
width="160"
:value="resetVisible[scope.$index]"
>
<p>确认重置此用户吗?</p>
<div style="text-align: right; margin: 0">
<el-button size="mini" type="text" @click="closeResetPopover(scope.$index)">取消</el-button>
<el-button type="primary" size="mini" @click="resetPassword(scope.row, scope.$index)">确定</el-button>
</div>
<a :class="$style.edit" slot="reference">重置密码</a>
</el-popover>
</template>
</el-table-column>
</el-table>
</template>
<script>
export default {
data() {
return {
visible: [],
resetVisible: [],
tableData: [
{
date: '2016-05-02',
name: '王小虎',
address: '上海市普陀区金沙江路 1518 弄'
},
{
date: '2016-05-04',
name: '王小虎',
address: '上海市普陀区金沙江路 1517 弄'
},
{
date: '2016-05-01',
name: '王小虎',
address: '上海市普陀区金沙江路 1519 弄'
},
{
date: '2016-05-03',
name: '王小虎',
address: '上海市普陀区金沙江路 1516 弄'
}
]
};
},
methods: {
closePopover() {
this.visible = [];
},
deleteUser(index) {
this.$set(this.visible, index, false);
},
closeResetPopover() {
this.resetVisible = [];
},
resetPassword(index) {
this.$set(this.resetVisible, index, false);
}
}
};
</script>