Answer the question
In order to leave comments, you need to log in
How to properly structure your vuex store?
There is storage on vuex. How do I get rid of this spaghetti?
state: {
data: {
city: {
name: null
},
list: [
{
deg: null,
dt: null,
humidity: null,
pressure: null,
speed: null,
temp: {
day: null,
eve: null,
max: null,
min: null
},
weather: [
{
description: null,
icon: null
}
]
},
{
deg: null,
dt: null,
humidity: null,
pressure: null,
speed: null,
temp: {
day: null,
eve: null,
max: null,
min: null
},
weather: [
{
description: null,
icon: null
}
]
},
{
deg: null,
dt: null,
humidity: null,
pressure: null,
speed: null,
temp: {
day: null,
eve: null,
max: null,
min: null
},
weather: [
{
description: null,
icon: null
}
]
},
{
deg: null,
dt: null,
humidity: null,
pressure: null,
speed: null,
temp: {
day: null,
eve: null,
max: null,
min: null
},
weather: [
{
description: null,
icon: null
}
]
},
{
deg: null,
dt: null,
humidity: null,
pressure: null,
speed: null,
temp: {
day: null,
eve: null,
max: null,
min: null
},
weather: [
{
description: null,
icon: null
}
]
}
]
}
},
Answer the question
In order to leave comments, you need to log in
You need to add another boolean field, for example isReady: false. In the action, when the date is stored in the store, set isReady: true, on the page itself, do computed:
{ isDataReady() { return this.$store.state.isReady ;}
It is quite possible to assign null
to state.data
, just then you need to check the presence of the fields you need in the state, for example:
or track the bug
let cityName;
try {
cityName = this.$store.state.data.city.name;
} catch (e) {
cityName = null;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question