Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

第 42 题:vue的8种通信机制 #61

Open
ravencrown opened this issue Sep 6, 2019 · 0 comments
Open

第 42 题:vue的8种通信机制 #61

ravencrown opened this issue Sep 6, 2019 · 0 comments

Comments

@ravencrown
Copy link
Owner

ravencrown commented Sep 6, 2019

vue 的8中通信方式

1. props / $emit
2. $children / $parent
3. provide/ inject:provide/ inject 是vue2.2.0新增的api, 简单来说就是父组件中通过provide来提供变量, 然后再子组件中通过inject来注入变量。
4. ref / refs
5. Vuex
6. $attrs与 $listeners
7. localStorage / sessionStorage
8. eventBus

总结

常见使用场景可以分为三类:

  • 父子组件通信: props; $parent / $children; provide / inject ; ref ; $attrs / $listeners
  • 兄弟组件通信: eventBus ; vuex
  • 跨级通信: eventBus;Vuex;provide / inject 、$attrs / $listeners

参考链接

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant