I have been learning to use vuex recently, and I want to use vuex to centrally manage state. When interacting with the background, it will inevitably involve interface calls. Such as async operations are usually written in action:
import Vue from 'vue'; import Vuex from 'vuex'; ('Vuex'); const actions = { getComplete ({}) { return new Promise((resolve, reject) => { ('XXXXXX').then((response) => { resolve(response); }).catch((response) => { reject(response); }); }); } } export default new ({ actions })
Here, the interface request is placed in the promise. Using the asynchronous feature of promise, the parameters returned after the interface call is successful can be obtained in the child component:
export default { ...... created: function() { this.$('getComplete').then(response => { ...... }).catch(response => { ...... }) } }
In addition to this method, you can also use the mapActions helper function to map the methods of the component into a call (you need to inject the store in the root node first). For details on the usage method, please refer to:
Portal:/en/
The above response method for obtaining actions in the vue component is all the content I share with you. I hope you can give you a reference and I hope you can support me more.