vue 2.0 Why is the event not triggered when using @click.self to bind itself?
Scenario:
Mobile terminal development, click on the mask layer to close the pop-up window, but the p box on the mask layer cannot be triggered, that is, the parent is triggered, and the event will not be passed to the child
Vue provides a .self modifier. It has been used before, but it suddenly doesn’t work this time. I don’t know what happened. . .
<!-- 只當事件在該元素本身(而不是子元素)觸發(fā)時觸發(fā)回調(diào) -->
<p v-on:click.self="close" ref="pop">
<button></button>
</p>
<!--
給組件綁定原生事件
有時候,你可能想在某個組件的根元素上監(jiān)聽一個原生事件??梢允褂?.native 修飾 v-on
-->
<my-component v-on:click.native.self="close"></my-component>
close(e) {
console.log(e.target)
this.$refs.pop.style.display = 'none'
}
Is your p box a sub-component? If it is a sub-component, I guess you need to add @click.native. The official document has it, search it.