兄弟组件传数据:
一:main.js中 定义全局事件:
new Vue({ render: h => h(App), // 传参用 beforeCreate() { Vue.prototype.$bus=this //全局事件总线 } }).$mount('#app')
二 事件发送数据组件:
change(){ this.$bus.$emit('hello', Date.now()) }s
三 接收数据组件
mounted(){ this.$bus.$on('hello',(data)=>{ this.name=data }) }
还一个办法 在main.js 中直接定义 window.datas={a:1} 不推荐