Vue传数据到后台后出现Uncaught (in promise) 的解决方法
在请求后面加catch(err=>{})即可。//报错的代码add(){this.$http.jsonp("http://localhost:8080/vueCRUD/add?name="+this.name+"&hp="+this.hp).then(res=>{if(res.body.status==0){//成功...
·
在请求后面加catch(err=>{})即可。
//报错的代码
add(){
this.$http.jsonp("http://localhost:8080/vueCRUD/add?name="+this.name+"&hp="+this.hp).then(res=>{
if(res.body.status==0){
//成功
//添加完成后,只需要手动再调用getHeroList()方法刷新列表
this.getHeroList();
}
else{
console.log("失败")
}
})
}
//解决方法
add(){
this.$http.jsonp("http://localhost:8080/vueCRUD/add?name="+this.name+"&hp="+this.hp).then(res=>{
if(res.body.status==0){
//成功
//添加完成后,只需要手动再调用getHeroList()方法刷新列表
this.getHeroList();
}
else{
console.log("失败")
}
}).catch(err=>{})
}
.catch(err=>{})
只要在后面加上.catch((e) => {}),就不会报错了,
更多推荐
已为社区贡献2条内容
所有评论(0)