E
E
eugenedrvnk2021-03-03 23:31:53
Vue.js
eugenedrvnk, 2021-03-03 23:31:53

At what stage to process data with API (vuex)?

I'm spinning pagination in the store and a small question arose.

An example of information returned from the back:

{last_page: 5, current_page: 1, per_page: 10, total: 100, count: 100, url: 'xyz.com'}


The view to which I will convert this information:
{lastPage: 5, currentPage: 1} // остальные поля не нужны


I call an action, in it I make a request to api, I get a result from the back containing fields I don't need. Those. I have to process it. Where is the best place to do it? Pass a full object to the mutation and already twist and process it in the mutation, or do the mutation in such a way that it would require an already prepared object and accordingly process this object in the action, and then pass its "beautiful" version into the mutation?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey delphinpro, 2021-03-04
@delphinpro

Do not do unnecessary things (make a "beautiful version"), but use the object as it is.
Or change the server part so that it gives the data in the format you need on the front.

A
Alexey Yarkov, 2021-03-04
@yarkov Vue.js

Write a function that will bring the data to the desired format and call it before the mutation.
But it's better to change the backend response, if there is access.

F
fallus, 2021-03-04
@fallus

Create a separate getter in the store that you need, which returns the data formatted by you.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question