vue2.0:子組件調用父組件


main.js文件添加如下:

new Vue({
router,
render: h => h(App),
data: {
eventHub: new Vue()
}
}).$mount('#app');

 

父組件:

監聽事件:

this.$root.eventHub.$on('cart.add', (target) => {
this._drop(target);
});

子組件:

觸發事件:

this.$root.eventHub.$emit('cart.add', event.target);

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM