诀窍1:使用el.contains(e) 来判断点击的区域
诀窍2:使用mouseup
诀窍3:完成之后,移除事件
showpopover (e) { this.popover = !this.popover var closePopover = (event) => { if (!this.$refs.popover.contains(event.target)) { this.popover = false document.body.removeEventListener(‘mouseup‘, closePopover) } } document.body.addEventListener(‘mouseup‘,closePopover) }
原文地址:https://www.cnblogs.com/CyLee/p/9049184.html
时间: 2024-10-12 15:56:57