1、vue2.x中,兄弟组件共享数据的方式 EventBus。
一、A组件
import eventBus from "@/components/eventBus";
export default {
methods: {
send() {
eventBus.$emit('share', this.str)
}
}
}
</script>
二、eventBus.js
import Vue from "vue";
export default new Vue()
三、B组件
<script>
import eventBus from "@/components/eventBus";
export default {
created() {
eventBus.$on('share', (val) => {
this.msgFormLeft = val
})
}
}
</script>
标签:vue,default,export,组件,共享,eventBus From: https://www.cnblogs.com/record-100/p/17823809.html