vue項目中使用axios設置攔截器

//http response 攔截器
axios.interceptors.response.use( (res)=> {
    // res.config.url.indexOf("api/monitorActiveTime")==-1
    if(res.config.headers.loading){
        endLoading();
    }
    if(res.data.code==-1){//token失效
        Message.error('登錄過期,請重新登錄');
        window.localStorage.removeItem("AITerminal_token");
        window.localStorage.removeItem("password");
        Router.push('/login');
    }
    return res;
},(error,status)=>{
    endLoading();
    if(axios.isCancel(error)){

    }else{
        if(error.response.status){
            return Promise.resolve(error.response);
        }else{
            Vue.Message.error({message: "網絡錯誤,請稍後再試",showClose:'true'})
        }
    }
    return Promise.reject(error);
    
});

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章