vue
created() {
document.addEventListener('click', this.clickOutsideEvent)
},
destroyed() {
document.removeEventListener('click', this.clickOutsideEvent)
},
methods: {
clickOutsideEvent(e) {
// console.log(this.$el.contains(e.target))
if (!this.$el.contains(e.target)){
this.handleOperater = false
}
}
}
html
//html
<div v-show="isShowDialog">
//js
document.addEventListener('click', (e) => {
if (!this.$el.contains(e.target)) this.isShowDialog = false;
})