Any way to pass data between non-related Vue components without using Event Bus?
up vote
1
down vote
favorite
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?
javascript vue.js vuejs2 vue-component
add a comment |
up vote
1
down vote
favorite
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?
javascript vue.js vuejs2 vue-component
I haven't used it so I can't be sure, but I think Vuex might be useful.
– The Guy with The Hat
Nov 14 at 19:49
@TheGuywithTheHat Thank you for the advise. After looking into vuex a little bit. I am almost sure that is want I need.
– Min XIE
Nov 14 at 23:17
The pure Vue approach is to use events. If you want a global variable manager then yes, Vuex is definitely what you need. In fact I'd recommend it anyway, it's quite powerful.
– Simon Hyll
Nov 15 at 2:34
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
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?
javascript vue.js vuejs2 vue-component
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?
javascript vue.js vuejs2 vue-component
javascript vue.js vuejs2 vue-component
asked Nov 14 at 19:00
Min XIE
477
477
I haven't used it so I can't be sure, but I think Vuex might be useful.
– The Guy with The Hat
Nov 14 at 19:49
@TheGuywithTheHat Thank you for the advise. After looking into vuex a little bit. I am almost sure that is want I need.
– Min XIE
Nov 14 at 23:17
The pure Vue approach is to use events. If you want a global variable manager then yes, Vuex is definitely what you need. In fact I'd recommend it anyway, it's quite powerful.
– Simon Hyll
Nov 15 at 2:34
add a comment |
I haven't used it so I can't be sure, but I think Vuex might be useful.
– The Guy with The Hat
Nov 14 at 19:49
@TheGuywithTheHat Thank you for the advise. After looking into vuex a little bit. I am almost sure that is want I need.
– Min XIE
Nov 14 at 23:17
The pure Vue approach is to use events. If you want a global variable manager then yes, Vuex is definitely what you need. In fact I'd recommend it anyway, it's quite powerful.
– Simon Hyll
Nov 15 at 2:34
I haven't used it so I can't be sure, but I think Vuex might be useful.
– The Guy with The Hat
Nov 14 at 19:49
I haven't used it so I can't be sure, but I think Vuex might be useful.
– The Guy with The Hat
Nov 14 at 19:49
@TheGuywithTheHat Thank you for the advise. After looking into vuex a little bit. I am almost sure that is want I need.
– Min XIE
Nov 14 at 23:17
@TheGuywithTheHat Thank you for the advise. After looking into vuex a little bit. I am almost sure that is want I need.
– Min XIE
Nov 14 at 23:17
The pure Vue approach is to use events. If you want a global variable manager then yes, Vuex is definitely what you need. In fact I'd recommend it anyway, it's quite powerful.
– Simon Hyll
Nov 15 at 2:34
The pure Vue approach is to use events. If you want a global variable manager then yes, Vuex is definitely what you need. In fact I'd recommend it anyway, it's quite powerful.
– Simon Hyll
Nov 15 at 2:34
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53307075%2fany-way-to-pass-data-between-non-related-vue-components-without-using-event-bus%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I haven't used it so I can't be sure, but I think Vuex might be useful.
– The Guy with The Hat
Nov 14 at 19:49
@TheGuywithTheHat Thank you for the advise. After looking into vuex a little bit. I am almost sure that is want I need.
– Min XIE
Nov 14 at 23:17
The pure Vue approach is to use events. If you want a global variable manager then yes, Vuex is definitely what you need. In fact I'd recommend it anyway, it's quite powerful.
– Simon Hyll
Nov 15 at 2:34