S
S
sir_pounce2020-11-24 23:02:51
Vue.js
sir_pounce, 2020-11-24 23:02:51

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

1 answer(s)
A
Alexey, 2020-11-25
@AlexeyCaTHaR

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)
      })
  }

Accordingly, only dispatch('getClients') would be called on the page\component.
But obtaining the keys of each client in the deployed area can be implemented through computed. And it is not necessary to download all the keys until someone has deployed the block.
PS> this is all just my IMHO at the moment

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question