vue+axios中的get请求传参,post请求头(form/json)不一样的传参的处理

<script>需要引入
import axios from 'axios'
import Qs from 'qs'(如果只是get请求就不需要引qs)
1.正常get请求:
     var params = {
        pageindex: _this.currentPage1-1,
        pagesize: _this.curPageSize1,
      }
      axios.get( "你请求的接口地址",
        params
      )
      .then(function(res){
      	_this.loading = false;
        _this.tableData = res.data.body.data.enterprise;
        _this.tableDataLength1 = res.data.body.data.total;
      })
      .catch(function (error) {
	   console.log(error);
	});
	
2.post的form请求头的请求处理:

	let data = {
	   'photo': url,
		'gender':gender,
		'source':"打零工APP",
		'wx_photo':"",
		'wx_nickname':""
	}
	axios({
	    headers: {
	        'Content-Type': 'application/x-www-form-urlencoded'
	    },
	    method: 'post',
	    url: '你请求的接口地址',
	    data: Qs.stringify(data)
	})
	.then(function (response) {
		console.log(response.data.status);
	  	if(response.data.status == 200){
			_self.$router.push({path: '/result'});
	  	}
	    
	})
	.catch(function (error) {
	    console.log(error);
	});
	
3.post的json请求头的请求处理:

	let datas = {
	  'isCms':"yes",
	  page_num: _this.currentPage1-1,
          num_page_each: _this.curPageSize1,
	}
	axios({
	    headers: {
	        'Content-Type': 'application/json;'
	    },
	    method: 'post',
	    transformRequest: [function (data) {
		    // 对 data 进行任意转换处理
		    return JSON.stringify(datas)
	    }],
	    url: '你请求的接口地址',
	    params: datas
	})
       .then(function(res){
	     _this.loading = false;
	     _this.tableData3 = res.data.body.data.result.users;
	     _this.tableDataLength1 = res.data.body.data.result.total;
        })
       .catch(function (error) {
	   console.log(error);
        });

完事,有更高的一定要记得分享给我哈

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值