Vue2组件间通信方式有哪些

105 阅读1分钟
  1. 父子组件:使用[props和emit]进行通信
  2. 爷孙组件: a.使用两次父子组件间进行通信 b.使用[provide + inject]来通信
  3. 任意组件:使用eventBus = new Vue()进行通信 a. 主要API是eventBus.oneventBus.on 和 eventBus.emit b. 缺点是事件多了就很乱,难以维护
  4. 任意组件:使用Vuex通信(Vue3可以用Pinia代替Vuex)