problem description
found that this attribute is not found in this.$router, then check that this is undefined
related codes
/ / Please paste the code text below (do not replace the code with pictures)
import axios from "axios"
import {Loading, Message} from" element-ui"
import Debounce from "lodash/debounce"
const Axios = axios.create ({
)baseURL:"/",
timeout:"10000",
responseType:"json",
withCredentials:true,
headers:{
"Content-Type":"application/json; charset=UTF-8"
}
});
let needLoadingRequestCount = 0;
let loadingObj;
Axios.interceptors.request.use (
)config=>{
console.log(this);
if(config.showLoading){
showFullScreenLoading();
}
return config;
},
error=>{
if(needLoadingRequestCount !== 0){
loadingObj.close();
}
Message({
showClose:true,
message:"",
type:"error"
});
return Promise.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 : "! "
});
if(res.data.code === 9999100){
this.$router.push("/login");
}
return Promise.reject(res.data.message);
}
return res;
},
error =>{
if(needLoadingRequestCount !== 0){
loadingObj.close();
}
Message({
showClose:true,
message:"",
type:"error"
});
return Promise.reject(error);
}
);
function showFullScreenLoading () {
if(needLoadingRequestCount === 0){
loadingObj = Loading.service({
lock:true,
text:"Loading",
spinner: "el-icon-loading",
background: "rgba(0, 0, 0, 0.7)"
});
}
needLoadingRequestCount PP
}
function tryHideFullScreenLoading () {
if(needLoadingRequestCount <= 0) return
needLoadingRequestCount --
if(needLoadingRequestCount === 0){
Debounce(tryCloseLoading,300)();
}
}
function tryCloseLoading () {
if(needLoadingRequestCount === 0){
loadingObj.close();
}
}
export default {
header(token){
Axios.defaults.headers.common["Authorization"] = `ticket ${token}`;
},
post:(url,data,config = {showLoading : true}) => Axios.post(url,data,config),
get:(url,config = {showLoading : true}) => Axios.get(url,config),
delete:(url,config = {showLoading : true}) => Axios.delete(url,config)
}
what result do you expect? What is the error message actually seen?
they are all arrow functions. How could this be lost