vue 2.0 @click.self does not trigger - Stack Overflow
代言
代言 2017-07-05 10:45:02
0
3
1144

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. . .

代言
代言

reply all(3)
过去多啦不再A梦
<!-- 只当事件在该元素本身(而不是子元素)触发时触发回调 -->
<p v-on:click.self="close" ref="pop">
    <button></button>
</p>

<!--

给组件绑定原生事件

有时候,你可能想在某个组件的根元素上监听一个原生事件。可以使用 .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.

迷茫

@click.native.self

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template