thu*_*hur 8 vue-resource vue-router vuejs2
我想在有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
}
});
});
Run Code Online (Sandbox Code Playgroud)
我该怎么做?
使用:Vue-router和Vue-resource
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(...)
}
});
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2923 次 |
| 最近记录: |