Home > Web Front-end > JS Tutorial > body text

How to use axios in vue components

亚连
Release: 2018-05-29 17:25:07
Original
3076 people have browsed it

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";
Copy after login

Different from many third-party modules, Axios cannot use the use method. Instead, you should perform the following operations

Vue.prototype.$axios = axios;
Copy after login

Then, we can use axios in App.vue

created:function(){
 this.$axios.get("/seller",{"id":123}).then(res=>{
  console.log(res.data);
 });
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template