vue中参数传不到后台去怎么办?

刚开始学习vue,遇到一个参数传不到后台去的问题~
问题代码是这样的:
checkin (){
var phoneNumber=this.phone;
var userpassword=this.yzm;
this.$http.post('myurl',{
mobilePhone:phoneNumber,
password:userpassword
}).then(function(res){
this.$root.userid=res.data.userid;
console.log(this.$root.userid)
this.$router.push('/content') ;
});
}
 
经过查询,添加了emulateJSON: true,就可以了,
这行代码能将参数们以json格式传到后台,后台才能接收到。
改好的代码如下:
checkin (){
var phoneNumber=this.phone;
var userpassword=this.yzm;
this.$http.post('my url',{
mobilePhone:phoneNumber,
password:userpassword
},{
emulateJSON: true
}
).then(function(res){
this.$root.userid=res.data.userid;
console.log(this.$root.userid)
this.$router.push('/content') ;
});
}
 
 
 
原文地址:https://www.cnblogs.com/ellenbaby/p/9006814.html