axios总结

GET数据格式
        get_be_data(){
                    axios({// (请求跨域请求线上数据 - 卖座)
                        url: 'https://m.maizuo.com/gateway',
                        headers: {//设置请求头用于跨域请求
                            'X-Client-Info': 
                            '{"a":"3000","ch":"1002","v":"5.0.4","e":"154549400038873748996477"}',
                            'X-Host': 'mall.film-ticket.film.list'
                        },
                        params: {//相当于ajax的data
                            cityId: 330100,
                            pageNum: 1,
                            pageSize: 10,
                            type: 1,
                            k: 7675918
                        }
                    })//axios相当于vue里面封装了promise对象
                        .then(res => console.log(res))
                        .catch(error => console.log(error))
                    }
POST数据请求格式
        postdata() {
                    var params = new URLSearchParams() //得到params对象,用来接收参数
                    // params.append( key, value )  key就是参数名,value就是参数值
                    params.append('a', 2)
                    params.append('b', 2)
                    axios({
                        url: 'http://localhost/Drafts/post.php',
                        method: 'post',
                        headers: {
                            'Content-Type': "application/x-www-form-urlencoded" 
                            //请求头设置为表单提交的请求头
                        },
                        data: params
                    })
                        .then(res => console.log(res))
                        .catch(error => console.log(error))
                    }

注意:Query String Parameters查询字符串参数用于get请求
Form Data 用于post请求

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值