I just started learning Vue and couldn't find an answer myself.
I have several arrays with data that will be loaded dynamically from the database. The objects inside them have an isLoaded property to identify the loading state.
The question is.
How can I change the value of isLoaded without passing the entire object to the mutation?
Like passing only the index and the name of an array.
Right now I do it like this:
export default new Vuex.Store({
state: {
books: [
{
id: 1,
title: 'Random',
img: '',
href: '/',
isLoaded: false
}
],
games: [
{
id: 1,
title: 'Random',
img: '',
href: '/',
isLoaded: false
}
]
},
getters: {
books(state) {
return state.books
},
games(state) {
return state.games
}
},
mutations: {
updateLoadStatus(state, item) {
item.isLoaded = true
}
}
})
The isLoaded prop is needed in order to add the preloader class.
<div :class="{loading: !book.isLoaded}">
<img :src="book.img" :alt="book.title" @load="updateLoadStatus(book)">
</div>
I have a lot more arrays than two, so I don't want do a separate mutation for each one.