問題描述在this.$router發(fā)現(xiàn)沒這個(gè)屬性,后面查了下this為undefined相關(guān)代碼//請(qǐng)把代碼文本粘貼到下方(請(qǐng)勿用圖片代替代碼)importaxiosfrom'axios'import{Loading,Message}from'element-ui'importDebouncefrom'lodash/debounce'constAxios=axios.create({baseURL:'/',timeout:'10000',responseType:'json',withCredentials:true,headers:{"Content-Type":"application/json;charset=UTF-8"}});letneedLoadingRequestCount=0;letloadingObj;Axios.interceptors.request.use(config=>{console.log(this);if(config.showLoading){showFullScreenLoading();}returnconfig;},error=>{if(needLoadingRequestCount!==0){loadingObj.close();}Message({showClose:true,message:'服務(wù)器有誤!請(qǐng)稍后重試',type:"error"});returnPromise.reject(error);});Axios.interceptors.response.use(res=>{//console.log(this);if(res.config.showLoading){tryHideFullScreenLoading();}if(res.data.code!==200&&res.data.message){Message({showClose:false,type:"error",center:true,message:res.data.message?res.data.message:"服務(wù)器繁忙!請(qǐng)重試"});if(res.data.code===9999100){this.$router.push('/login');}returnPromise.reject(res.data.message);}returnres;},error=>{if(needLoadingRequestCount!==0){loadingObj.close();}Message({showClose:true,message:'服務(wù)器繁忙!請(qǐng)稍后重試',type:"error"});returnPromise.reject(error);});functionshowFullScreenLoading(){if(needLoadingRequestCount===0){loadingObj=Loading.service({lock:true,text:"Loading",spinner:'el-icon-loading',background:'rgba(0,0,0,0.7)'});}needLoadingRequestCount++}functiontryHideFullScreenLoading(){if(needLoadingRequestCountAxios.post(url,data,config),get:(url,config={showLoading:true})=>Axios.get(url,config),delete:(url,config={showLoading:true})=>Axios.delete(url,config)}你期待的結(jié)果是什么?實(shí)際看到的錯(cuò)誤信息又是什么?明明都是箭頭函數(shù)啊,this怎么會(huì)丟呢
Axios配置文件中this為undefined?
寶慕林4294392
2019-05-11 16:21:41