标签:ref 包含 ted nta create add 绑定 html 查看
<div id="box" style="width:110px;height:110px;background-color:red"></div>
document.addEventListener(‘click‘,(e)=>{
alert(‘zhixing‘)
var box = document.getElementById(‘box‘);
if(box.contains(e.target)){
alert(‘在内‘);
}else{
alert(‘在外‘);
}
})
<div id="box" ref="box" style="width:110px;height:110px;background-color:red"></div>
created(){
document.addEventListener(‘click‘,(e)=>{
console.log(this.$refs.box.contains(e.target));
if(!this.$refs.box.contains(e.target)){
this.isShowDialog = false;
}
})
}
原文:https://blog.csdn.net/cxz792116/article/details/79415544
给最外层的div加个点击事件 @click="userClick=false"
给点击的元素上面加上:@click.stop="userClick=!userClick" //vue click.stop阻止点击事件继续传播
或者给子元素js事件里
click(e)=>{
e.stopPropagation();//阻止事件冒泡
this.userClick = !this.userClick;
}
标签:ref 包含 ted nta create add 绑定 html 查看
原文地址:https://www.cnblogs.com/MisterHe/p/10291354.html