常用组件通信方式

1、父组件=>子组件 props

2、子组件=>父组件 .$emit() .$on()

3、兄弟组件:event-bus

const bus=new Vue();
Vue.prototype.$bus=bus;

4、vuex

5、跨级组件:provide/inject

6、ref /$parent / $children

<component-a ref="child" ></component-a>
const dom=this.$refs.child;
//dom指向的是DOM元素或者组件实例
//$parent / $children 则可以访问父子实例,可以直接访问数据和调用方法。

7、插槽

原文地址:https://www.cnblogs.com/annie211/p/12661855.html