vue修改http请求头_Vue中Http请求的那些坑 【转载】

1.不支持http请求

表现为:程序启动正常,点击按妞不跳转,后台无响应,浏览器调试出现

Uncaught TypeError: Cannot read property 'post' of undefined

解决办法:添加vue-resource支持,在main.js添加

import VueResource from 'vue-resource'

Vue.use(VueResource);

2.post请求,后台接收参数为null

表现为:后台响应但是参数为null,正确的登陆失效,调试时,参数为from object

解决办法:http请求中,添加

{emulateJSON:true}

全部的Http请求部分代码为

_this.$http.post('http://localhost:8080/person/login', {

username: _this.username,

password: _this.password

}

,{emulateJSON:true}

)

.then(function (response) {

var errorcode = response.data.code;

if (errorcode == "200") {

_this.$router.push(

{ path: '/HelloWorld',

query: {

user: response.data.data,

}

});

} else {

_this.$router.push({ path: '/Fail' });

}

})

.catch(function (error) {

console.log(error);

});

3、正确处理后,跳转到空页面

原因:路由的url配置有问题,注意组件的引用的对应关系以及path的路径问题

4.Request请求变成Options

解决办法:设置头格式

http: {

headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}

},

转载时请注明出处及相应链接,本文永久地址:https://blog.yayuanzi.com/24554.html

微信打赏

支付宝打赏

感谢您对作者Elaine的打赏,我们会更加努力!    如果您想成为作者,请点我

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值