路由攔截器vue
router.beforeEach((to,from,next)=>{ if(to.path=='/login' || localStorage.getItem('token')){ next(); }else{ alert('請從新登陸'); next('/login'); } })
請求攔截器ios
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); });