data() { return { menuShow: false //v-show標識隱藏顯示 } }, mounted (){ let _this = this; document.addEventListener('click', function (e) {
// 下面這句代碼是獲取 點擊的區域是否包含你的菜單,如果包含,說明點擊的是菜單以外,不包含則為菜單以內 let flag = e.target.contains(document.getElementsByClassName('menu-class')[0]) console.log(flag) if(!flag) return _this.menuShow = false }) }