- props $emit v-model 实现一层子级父级传递。
- $children $parent 返回的是一个组件集合,但是需要手动添加下标,不推荐使用(组件一但很多,不利于维护)。
- eventBus 用于兄弟之间传递,可以嵌套多层传递。
- provide inject 以允许一个祖先组件向其所有子孙后代注入一个依赖,不论组件层次有多深。
- $attrs $listeners 可以多层向下传递,并且孙子组件可直接调用爷爷组件方法。
- $ref 直接调用组件原型方法和属性。
源码地址:github
https://github.com/mr-zxy/vue-communication