- 点击下拉以外的页面 下拉框隐藏掉
mounted() {
// 全局监听
document.addEventListener('click', this.bodyCloseMenus)
},
methods: {
//控制状态
bodyCloseMenus() {
if (this.searchInputShow == true) {
this.searchInputShow = false
}
},
}
beforeDestroy() {
// 销毁
document.removeEventListener('click', this.bodyCloseMenus)
},
- 点击input 也会关闭下来 添加 @click.stop 防止冒泡