1.给点击事件加.stop阻止事件
2. 设置一个变量为false,默认隐藏
3.在点击事件中,加如下代码:
showNavBar() {
var that = this
this.showNavbar = !this.showNavbar
// 给全局设置了点击事件,上面绑定的点击事件,需要加个click.stop 阻止事件
document.addEventListener('click', function (e) {
// console.log(e)
// 样式隐藏操作
that.showNavbar = false
// document.getElementById('showNav').style.display = 'none';
}, false)
}