如题,我在自定义组件标签上绑定了事件,点击时却无法触发,代码如下:
<template id="test"&g; <p>Hi</p> </template> <div id="app"> <test @click="hello"></test> </div>
Vue.component('test', { template: "#test" }) new Vue({ el: '#app', data: {}, methods: { hello: function() { alert(); } } })
然鹅,我把 @click 放到父级标签上却又可以触发了,这是为啥?
<div id="app" @click="hello"> <test></test> </div>
![]() | 1 zhuangtongfa 2017-02-07 17:11:18 +08:00 ![]() @click.native 试试 |
![]() | 2 matts8023 OP @zhuangtongfa 嗯,刚刚在 Vue 官方库的 issue 中找到,可以用,谢谢 O(∩_∩)O |
![]() | 5 yunkou 2017-02-07 20:36:52 +08:00 官方文档有说明哦 |