axios请求设置header信息方法

  • 传递的参数顺序应该是:第一个是路径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);
		})
		}
  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值