赞
踩
el-popover中嵌套使用el- select,当鼠标移除el-popover一秒后关闭el-popover。
1、el-popover使用手动模式
<el-popover trigger="manual" v-model="visible"> <div ref="popoverRef"> <el-select v-model="value1"></el-select> <el-select v-model="value2"></el-select> </div> <el-button slot="reference" @click="visible=!visible"></el-button> </el-popover> // javascript this.$refs.popoverRef.addEventListener('mouseleave', (e) => { this.time = 0; setTimeout(() => { ++this.time; if (this.time == 1) { this.visible = false; } }, 1000) })
这里会出现一个问题!el-select选项展开的时候它是插入body的,所以选择选项的时候会移除popoverRef的范围
这里我加了一个字段判断select是否打开,通过select的visible-change的值来修改
<el-select v-model="value1" @visible-change="selectStateChange"></el-select>
// javascript
selectStateChange (val) {
this.selectOpen = val;
},
当鼠标快速移出再移入的时候则需要取消计时。
完整的代码如下:
<el-popover trigger="manual" v-model="visible" @show="onShowPopover" @hide="onHidePopover"> <div ref="popoverRef"> <el-select v-model="value1" @visible-change="selectStateChange"></el-select> <el-select v-model="value2" @visible-change="selectStateChange"></el-select> </div> <el-button slot="reference" @click="visible=!visible"></el-button> </el-popover> // javascript onShowPopover () { this.$refs.popoverRef.addEventListener('mouseleave', (e) => { this.time = 0; this.timeOut = setTimeout(() => { ++this.time; if (this.time == 1 && !this.selectOpen && !this.inPoPover) { this.visible = false; } }, 1000) }) this.$refs.popoverRef.addEventListener('mouseenter', (e) => { this.inPoPover = true; }) } onHidePopover () { clearTimeout(this.timeOut); } selectStateChange (val) { this.selectOpen = val; },
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。