发出未在 VueJS 中注册?
Emit not registering in VueJS?
我试图在父元素中创建一个简单的函数,当它从子元素获得一个 emit 时更新一个变量。我已经坚持了 2 个小时,我受够了,因为我知道答案会如此简单。
有问题的代码:
子元素:
<div v-on:click="$emit('event1')">
Click
</div>
父元素:
<p @event1="test()"></p>
<Section /> // the child element
methods: {
test() {
console.log("test")
},
}
上面的代码没有记录任何内容。我将其设置为最小值,因为没有外部因素会改变代码的结果。
提前致谢!
事件侦听器必须附加到您的 <Section />
元素,event1
不会全局发出
我试图在父元素中创建一个简单的函数,当它从子元素获得一个 emit 时更新一个变量。我已经坚持了 2 个小时,我受够了,因为我知道答案会如此简单。
有问题的代码:
子元素:
<div v-on:click="$emit('event1')">
Click
</div>
父元素:
<p @event1="test()"></p>
<Section /> // the child element
methods: {
test() {
console.log("test")
},
}
上面的代码没有记录任何内容。我将其设置为最小值,因为没有外部因素会改变代码的结果。
提前致谢!
事件侦听器必须附加到您的 <Section />
元素,event1
不会全局发出