Answer the question
In order to leave comments, you need to log in
How to build an application on vue?
Actually, the bottom line is that 2 arrays come from the server. The first is an array of clients as objects. The second is an array of keys (also in the form of objects) that belong to them. They need to be displayed in a table with folding lines (in the line itself, infa about clients, in its "folding" part, a list of their keys). The table is implemented as a separate component. But the data comes in a form that is not suitable for it, they need to be formed into one array of clients, where each client object will be expanded with an array of keys. Actually questions:
Where it is better and more correct to receive these arrays of clients and their keys. In the store, in the page view, or in a separate service?
And where to perform their "gluing"?
Where to make a request to the server with changed data from the table (the table emits a line and substring change event)?
Is it generally correct to write methods in the page component (src/views in the template)?
Answer the question
In order to leave comments, you need to log in
I would implement getting data only on the page/component where it is needed. And depending on this, it would be clear, according to some event on the page or in the hook, it is necessary to receive data.
Receiving would be implemented through an action in the store. Something like this:
getClients ({ commit, dispatch }) {
commit('setLoading', true) // preloader
api.getClients ()
.then((clients) => {
commit('setClients', clients)
dispatch('getKeys')
})
.finally(() => {
commit('setLoading', false)
})
},
getKeys({ commit }) {
commit('setLoading', true)
api.getKeys()
.then((keys) => {
commit('setKeys', keys)
})
.finally(() => {
commit('setLoading', false)
})
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question