The content of this article is about Vue’s loading effect based on vuex and axios interceptor and the installation configuration of axios. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you. .
Preparation
Use vue-cli scaffolding to create a project
Enter the project to install vuex and axios (npm install vuex,npm install axios)
axios configuration
Install in the project After the axios module (npm install axios) is completed, perform the following configuration:
main.js
1 2 3 4 5 |
|
loading component
I choose to use the loading component provided by iview here.
1 2 3 4 5 6 |
|
After installation and introduction, write loading as a component loading.vue
Vuex state setting controls the visibility of loading
##store.js(Vuex)
1 2 3 4 5 |
|
1 |
|
The component uses axios to request data
1 |
|
1 2 3 4 5 6 7 8 9 10 11 |
|
Axios interceptor configuration
main.js
1 2 3 4 5 6 7 8 9 10 |
|
Special attention: There is a syntax pit here (I stepped on it many times). The data in main.js that is called and manipulated in vuex state is different from this.$store.state in the component, but directly store.state Same as the above code
Effect display
Vue configuration axios method step example
Implement animation switching function based on Vue, Vuex, and Vue-router
The above is the detailed content of Vue implements loading effects and axios installation configuration based on vuex and axios. For more information, please follow other related articles on the PHP Chinese website!