一、导航守卫
导航守卫主要用于实现在页面发生跳转时,检测token的存在,如果token没有或失效,网页则回到登录页面,代码如下。
router.beforeEach((to,from,next)={lettoken=localStorage.getItem(token);console.log(token)if(token
to.path===/){next();}else{next({path:/});}})
二、封装请求方法
在教务管理系统中,我们需要自己封装请求方法,以完成一些麻烦的任务,封装的代码如下。
importaxiosfromaxiosconstservice=axios.create({baseURL: