vue-axios的使用

vue-axios中文网:http://www.axios-js.com/zh-cn/docs/vue-axios.html安装npm install --save axios vue-axios将下面代码加入入口文件import Vue from vueimport axios from axiosimport VueAxios from v...

vue-axios中文网:http://www.axios-js.com/zh-cn/docs/vue-axios.html

安装

npm install --save axios vue-axios

将下面代码加入入口文件

import Vue from 'vue'
import axios from 'axios'
import VueAxios from 'vue-axios'

Vue.use(VueAxios, axios)

发送axios请求

  1. get请求
	this.axios({
        method: "get",
        url: "http://localhost:8081/user/regist?name="+this.username+"&age="+this.age,
      }).then(function (response) {
        console.log(response.data);
      });
  1. post请求
	this.axios({
        method: "post",
        url: "http://localhost:8081/user/regist",
        data:{
          username:this.username,
          age:this.age
        }
      }).then(function (response) {
        console.log(response.data);
      });

本文标题为:vue-axios的使用

基础教程推荐