A
A
Andrey Suha2020-02-20 13:55:37
webpack
Andrey Suha, 2020-02-20 13:55:37

Can I somehow set the order of initialization of vue components?

there is such a structure

<div id="app">
        <first-component></first-component>
        <second-component></second-component>
        <third-component></third-component>
    </div>


Components are registered like this

Vue.component("first-component", () => import(`first-component-path.vue`));
Vue.component("second-component", () => import(`second-component-path.vue`));
Vue.component("third-component", () => import(`third-component-path.vue`))


Inside the first-component, the module is re-sourced to vuex, which is then used in the other two components. The problem is that the third-component is initialized before the other two, respectively, at the time of its initialization, there is no module in vuex yet, and when I try to access it, I get an error. How can this be fixed?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex, 2020-02-20
@andreysuha

With such an architecture, it is impossible.
You have three asynchronous components. Each component is loaded independently, and rendered when it is loaded. Your components should remain completely independent of each other.
Your problem is that the module in vuex depends on the component. And it shouldn't be. Load vuex before and only then initialize the components.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question