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请求
- get请求
this.axios({
method: "get",
url: "http://localhost:8081/user/regist?name="+this.username+"&age="+this.age,
}).then(function (response) {
console.log(response.data);
});
- 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);
});