the original problem is to click on the parent component anywhere to make the child component disappear. There is a big guy"s code that reads and asks him that he didn"t answer, so there are two places I don"t know. I would like to ask you
why this code is written into beforeMount? Didn"t you mount beforeMount at the time? the click event can"t be used, is it? And what is the _ close
here?
<template>
<div @click="none">
<div id="drop-down">
<Dropdown v-if="dd"></Dropdown>
</div>
</div>
</template>
export default {
name: "Blog",
data () {
return {
dd: true
}
},
methods: {
none () {
this.dd = false
}
},
Boss"s component code
beforeMount() {
this._close = e => {
//
if (this.$el.contains(e.target)) {
return;
}
this.$emit("hide");
};
document.body.addEventListener("click", this._close);
},
beforeDestroy() {
document.body.removeEventListener("click", this._close);
}