有一个需求:
后端返回状态码-999表示token过期,前端要跳到登录页。
我的代码:
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)
});提示了一句“Cannot read property '$router' of undefined”
慕姐4208626
倚天杖
白衣染霜花
随时随地看视频慕课网APP
相关分类