Home > Article > Web Front-end > How to use axios in vue components
Below I will share with you an article on how to use axios in vue components. It has a good reference value and I hope it will be helpful to everyone.
Now we have built a vue project framework through webpack vue-cli. What should we do if we need to use axios in the vue component to obtain data from the background?
Normally, the project directory we built should look like this
First we need to install axios, which will be npm Everyone knows
The next step is to introduce axios in main.js
import axios from "axios";
Different from many third-party modules, Axios cannot use the use method. Instead, you should perform the following operations
Vue.prototype.$axios = axios;
Then, we can use axios in App.vue
created:function(){ this.$axios.get("/seller",{"id":123}).then(res=>{ console.log(res.data); }); }
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
The problem of adding expressions to v-show in Vue (determining whether to display)
Using iview in vue Define verification keyword input box problems and solutions
About the difference between v-if and v-show in vuejs and the problem that v-show does not work
The above is the detailed content of How to use axios in vue components. For more information, please follow other related articles on the PHP Chinese website!