Vue.js drop-down box component closes the menu when clicking outside the menu bar Author: Chuwen Time: 2021-08-23 Classification: Vue.js , JavaScript ## Menu.vue >Menu Components > ! []( https://cdn.nowtime.cc/2021/08/23/2193569241.png ) ``` <template> <div class="menu" v-if="show"> <!-- Suppose it is a menu component... --> </div> </template> <script> export default { data(){ return { Show: true,//Whether to display the menu } }, mounted() { //Just add it here document.addEventListener('click', (e) => { //If the DOM of the current component (menu component) "does not contain" the currently clicked DOM //Close the display menu if (!this.$el.contains(e.target)) this.show = false }) } } </script> ``` label: Vue.js , assembly