说明:vue使用时,当突然断网或其他原因造成数据加载错误时,axios方式的catch处理;
//取出内容;
getItems:function(kid){
var that = this;
that.action='default';
that.loading = true;
that.finished = false;
that.isfisrsload=false;
that.tabitems=[];
axios.get(allApi.itemsList,
{params: {cat_id: kid,action:'type'},
headers:{token:token,id:manage_id}})
.then(function (res) {
that.loading = false;
that.finished = true;
if (res.data.code == 0) {
that.tabitems = res.data.data;
that.action='items';
if(that.tabitems.length<=0){
that.isfisrsload=true;
}
}
}).catch(function (res) {
that.loading = false;
that.finished = true;
that.tabitems =[];
if(that.tabitems.length<=0){
that.isfisrsload=true;
}
});
},
本文详细介绍了在Vue项目中,使用Axios进行数据请求时如何处理因断网或其它原因导致的数据加载错误。通过catch函数,实现了加载状态的正确更新及错误情况下的数据清空,确保了应用的稳定性和用户体验。
1219

被折叠的 条评论
为什么被折叠?



