Vue登陆界面登陆成功没法跳转

 
 

     前言: vue

           在试着用vue写一个登陆页面,已经调试好了,登陆成功后,跳转到主页面。可是加了拦截器后,不会跳到主页面ios

 this.$axios.post(domain.publicUrl+'/login',
                    this.$qs.stringify(data1)).then(res=>{
                      if(res.data.code===200){             
                          this.$router.replace('/main'),
              window.localStorage["token"]=JSON.stringify(res.data.data.token);

                      }else {
                          this.$message({
                              type:"info",
                              message: res.data.msg
                          });
                      }
                });

       2、在这种状况下登陆功能,跳转都正常,后来加入了拦截器,代码以下:axios

router.beforeEach((to, from, next) => {
  if (to.meta.requireAuth) {  // 判断该路由是否须要登陆权限
    if (localStorage.token) {  // 获取当前的token是否存在
      console.log("token存在");
      next();
    } else {
      console.log("token不存在");
      next({
        path: '/login', // 将跳转的路由path做为参数,登陆成功后跳转到该路由
        query: {redirect: to.fullPath}
      })
      return;
    }
  }

          加入拦截器后,拦截功能正常,跳转功能不正常了,一直都在登陆界面,登陆成功,token也写入缓存了,可是就是不会跳转,看拦截器代码也没问题,后来看登陆的代码才发现了问题所在。个人跳转的代码是在写token以前的。因此跳转到main页面的时候,没有token就又返回到login页面,而后一直循环了。查了半天。哈哈哈 。。。  十一假期要结束了呀,没出去玩,快点上班吧。缓存