有没有一种方法可以不创建函数或$on直接接收值? 诸如此类:
<my-custom-component @saved="data => variable = data"></my-custom-component>
That works. 有什么问题吗?
密码
Vue.component('my-custom-component',{ template : `<button @click='$emit("saved",{data : "hello cobber"})'>Click me !</button>` }) vm = new Vue({ el : '#vueRoot', data : { variable : null } })
加成
<div id="vueRoot"> <my-custom-component @saved="data => variable = data"></my-custom-component>{{variable}} </div>