vueルーティングブロッカーとリクエストブロッカー
663 ワード
vueブロッキングルーティングブロック は、ガイド にルーティングする.要求ブロッキング この機能は、要求の送信時にトリガーする.
router.beforeEach((to,from,next)=>{
if(to.path=='/login' || localStorage.getItem('token')){
next();
}else{
alert(' ');
next('/login');
}
})
axios.interceptors.request.use(function (config) {
let token = window.localStorage.getItem("token");
if (token) {
config.headers.token = token; // token
}
return config; // config
}, function (error) {
return Promise.reject(error);
});