there is a requirement:
the backend return status code-999 indicates that the token expires and the front end needs to skip to the login page.
my code:
http.js
import axios from "axios"
import Vue from "vue"
import VueRouter from "vue-router"
import { Message } from "element-ui";
import common from "./global.js"
Vue.use(VueRouter)
axios.interceptors.response.use(
response => {
//token
if(response.data.code == -999){
Message({
message: ",!",
type: "warning"
});
this.$router.push("/login");
this.common.delCookie("token");
this.common.delLocal();
}
return response;
},
error => {
Message({
message: "",
type: "warning"
});
return Promise.reject(error.response.data)
});
prompted "Cannot read property"$router" of undefined"