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