在请求后面加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) => {}),就不会报错了,
版权声明:本文为jhjyfjy原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。