interview-answe icon indicating copy to clipboard operation
interview-answe copied to clipboard

203.[vue]Vue 组件如何通信?

Open webVueBlog opened this issue 5 years ago • 1 comments

[vue]

webVueBlog avatar Apr 21 '20 01:04 webVueBlog

父子组件:父 => 子 使用 props ,子 => 父 使用 $on 与 $emit (简易的发布订阅模式)

获取父子组件实例:$prarent 、$children (组件初始化时获取)

在父组件中提供数据子组件消费:Provide 与 Inject

1.Provide :将provide数据写到当前组件实例上 2.Inject:遍历父组件查找 provide 数据(响应式数据) 3.多用于写插件

Ref 获取组件实例,调用属性与方法

event bus 事件总线实现跨组件通信 ,Vue.prototype.$bus = new Vue( )

Vuex 状态管理实现

webVueBlog avatar Apr 21 '20 01:04 webVueBlog