组件通信 eventtBus
生活随笔
收集整理的這篇文章主要介紹了
组件通信 eventtBus
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
平級組件的通信 一個(gè)全局發(fā)布訂閱模式,它是掛載到全局的
<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>組件通信 &bus</title><script src="./node_modules/vue/dist/vue.js"></script> </head> <body><div id="app"><children1></children1><children2></children2></div> </body> <script>//發(fā)布訂閱模式//適合簡單的數(shù)據(jù)流Vue.prototype.$bus = new Vue();Vue.component('children1',{template:`<div><span>children1</span></div>`,mounted() {this.$bus.$on('吃',(food)=>{console.log(food)}) },})Vue.component('children2',{template:`<div><span>children2</span></div>`,mounted() {this.$bus.$emit('吃','月餅')},})let vm = new Vue({el:'#app',})//hello </script> </html>?
轉(zhuǎn)載于:https://www.cnblogs.com/guangzhou11/p/11540050.html
總結(jié)
以上是生活随笔為你收集整理的组件通信 eventtBus的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 组件通信 $ref
- 下一篇: vue token 过期处理