M
M
Magnus Keef2020-12-12 19:14:38
Vue.js
Magnus Keef, 2020-12-12 19:14:38

How to wait for data in store and use it in beforeMount?

Now I have a method in beforeMount that uses data from the store
. When the component is loaded for the first time, this method in beforeMount fires, but the data has not yet arrived in the store.

I'm trying to watch store changes via vm.$watch(spyData, myMethod)

But that doesn't solve the problem

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Magnus Keef, 2020-12-14
@SecurityYourFingers

1. made spyData a computed property
2. in beforeMount() made a check:
spyData.length > 0 ? myMethod() : null
3. And accordingly, beforeMount() already had:
vm.$watch(spyData, myMethod)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question