- 传递的参数顺序应该是:第一个是路径Url,第二个是参数data,第三个是header(个人理解)
- post请求
getList(){
let url='';
let option4=[];
url=this.$base_url + '/version/list';
let criteria=JSON.stringify({id:this.form.region});
this.$axios.post(url,criteria,{headers: {'Content-Type': 'application/json'}})
.then(response => {
this.option2=response.data.data;
});
}
get请求
return axios.get(url, {
params: data,
headers: {'yl-authorization': this.token}//设置header信息
}).then((res) => {
this.plList = res.data;
if (this.plList.length < this.size) {
this.jiazai = '没有更多数据啦~~~'
}else {
this.jiazai = '点击加载更多'
}
})
请求头Content-Type为’application/x-www-form-urlencoded‘
axios(){
axios({
url:'api/json.php',
method: 'post',
data: {n:1},
headers:{
'Content-Type':'application/x-www-form-urlencoded'
}
})
.then(respanse=>{
console.log(respanse.data);
})
}