javascript - If all requests are placed in actions, where should the obtained data be placed, state or data in the vue instance?
滿天的星座
滿天的星座 2017-06-13 09:24:10
0
4
999

Like the title
I saw someone put all the requests into the vuex action, but I want to ask if the data is used to change the state? But isn't the state used to transfer the state? Is this excessive use of vuex to store data? Can you please give me an answer?

滿天的星座
滿天的星座

reply all(4)
迷茫

It depends on the requirements. If you have several components sharing the requested data, you should put it into vuex for state management. If only one component uses the requested data, there is no need to put it into vuex.

扔个三星炸死你

Put the data request in the action, then commit the data to the mutation to change the state, and then the component can obtain it in the following way

computed: {
    ...mapState({
        'user'
    })
}

One of the benefits of vuex is the data sharing and communication between components among brothers. There is no need to put all data in vuex.

我想大声告诉你

You can use Vuet with route rules to implement management page requests. You can take a look at this simple example

代言

This really depends on your own data needs
There may be two types of data at this time.
1. Global data, this kind of data will be passed between each component. If this kind of data is only placed in the data of the component, then it will be more troublesome for your other components to use the data of this component. It is recommended to put this kind of data into state, so that it will be much more convenient for other components to retrieve the data. And various calculations can be applied.
2. Local data. This kind of data is unique data within the component. It is not used elsewhere. It doesn’t matter if you put this kind of data into the global state or the data of the component. But you can’t blindly put everything in the state. Over time, your state data will become messy. Therefore, the key is to store data according to the situation.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!