|
vue中axios引用
import axios from 'axios' axios.defaults.baseURL="http://localhost:8888"; Vue.prototype.$axios = axios axios 传值 get方式 : 1. url后面加参数 this.$axios.get("http://localhost:8888/select.do?username='hahha'"); 2. paramsthis.$axios.get("http://localhost:8888/select.do",{
params:{
username:"hahah"
}
});post方式: 1. 字符串形式 this.$axios.post("http://localhost:8888/postselect.do","username='hahha'");2. transformRequest方式(方法自己写) this.$axios.post("http://localhost:8888/postselect.do",{username:'hahha'} ,{
transformRequest:[
function(data){
// username=hahha&age=18
let params = "";
var arr = [];
for(var key in data){
arr.push(key+"="+data[key]);
}
params = arr.join("&");
return params;
}
]
}); 3. 使用qs模块(需要安装qs) import qs from 'qs'
this.$axios.post("http://localhost:8888/postselect.do",qs.stringify({username:'hahha'}));4. 使用JSON.stringify (直接使用,推荐) import qs from 'qs'
this.$axios.post("http://localhost:8888/postselect.do",JSON.stringify({username:'hahha'})); |
|
最新喜欢: |
|
沙发#
发布于:2019-05-23 11:44
最新版本,对象可以直接传,不用转换了
|
|
|