Home>Article>Web Front-end> How to communicate in different situations in vue? way to share
How to communicate in different situations in vue? The following article will analyze the communication methods in different situations invue. I hope it will be helpful to everyone!
In fact, everyone is familiar with component communication in vue. Even if you open your mouth, after all, this is what is often asked in interviews. Since I had not considered it carefully before, when I was writing a small project, I encountered the need for communication in components, and then I started writing it. It turned out that it was useless. After checking for a long time, I realized that that method was not suitable for this situation. So after this incident, I decided to write an article to classify communication methods more clearly and carefully. After all, not every communication method is suitable for all scenarios. (Learning video sharing:vuejs tutorial)
Same What is mainly involved in the same page tab of the browser is the value transfer between parent and child components.
You probably don’t know the concept of a state manager. strangeness.
This pair Options need to be used together to allow an ancestor component to inject a dependency into all its descendants, no matter how deep the component hierarchy is, and for as long as the upstream and downstream relationships are established.
provide
andinject
bindings are not responsive. However, if you pass in a listenable object, the object's properties are still responsive.// parent.vue // 此处忽略template模板的东西
// child.vue // 此处忽略template模板的东西
Serious props/$emit are too common, and they are all overused, so there is no need to write sample code.
Problem:
// utils/eventBus.js import Vue from 'vue' const EventBus = new Vue() export default EventBus
// main.js // 进行全局挂载 import eventBus from '@/utils/eventBus' Vue.prototype.$eventBos = eventBus
// views/parent.vue