First I want to be clear why I don't want to use Event Bus in this situation: Because Event Bus won't work for this situation!
Please see the simplified structure of my Vue.js Project first:
App.vue
|---Map.vue
|---Info.vue
| |---layerInfo.vue
|
|---WMS.vue
|---WFS.vue
|---Basic.vue
The diagram only shows which component creates which child component, but they are not all created at the start of the Vue app. The layerInfo.vue will only be created when some conditions are filled (You can image only after the use click the button, the layerInfo.vue will be rendered/created)
What have I done:
In Map.vue component, I have created a Object map, which contains the useful information, and I $emit the map to a Global Event Bus.
The Problem is, at this momente, the layerinfo.vue doesn't exist. So I can't listen to the $emit event use $on. (Even I tried, I didn't get the map)
And a further question about Event Bus: I used Event Bus in my other part of the vue app. But I am still confused, if the Event Bus makes a two-way-data-binding or only one-way? My conclusion: global Event Bus can only be userd to pass data between two non-related components when they both exist.
But my question is: how I can then pass date between two non-related components when I don't know when the one that needs to receive the data will be created / rendered?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.