when the vue project login jumps to the home page, it is redirected to the login interface. The next error report is
.
analyzed that the following reason may be caused by the interceptor"s status 401. After I removed the interceptor, I jumped to the home page and refreshed the data several times. The token is stored normally. The login jump code is as follows
.then(response => {
localStorage.setItem("token", response.data.result.authToken);
this.$router.push(this.$route.query.redirect || "/");
})
interceptor
axios.defaults.headers.common["Authorization"] = localStorage.getItem("token")
axios.interceptors.response.use(
response => {
return response
},
error => {
if (error.response) {
switch (error.response.status) {
case 401:
router.replace({
path: "/login",
})
}
}
return Promise.reject(error.response.data)
})
how should I handle it? thank you for your answer