我希望在拥有401时重定向用户,但我无法从此上下文访问router
:
Vue.http.interceptors.push(function(request, next) {
// continue to next interceptor
next(function(response) {
if(response.status == 401){
//redirect user here
//tried: Vue.$router and Vue.$route
}
});
});
我该怎么做?
使用:Vue-router和Vue-resource
答案 0 :(得分:6)
const router = new VueRouter({
routes
})
Vue.http.interceptors.push(function(request, next) {
// continue to next interceptor
next(function(response) {
if(response.status == 401){
router.push(...)
}
});
});