阅读 48

vue项目遇到的问题总结

addRoutes多次添加路由重复问题(参照vue-element-admin项目)

  1. router.js添加重置路由方法
import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

const createRouter = () =>
  new Router({
    mode: "hash",
    routes: []
  });
const router = createRouter();

export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}
export default router;
复制代码
  1. 在登出模块调用
import { resetRouter } from "@/router";

 Logout({ commit, state }) {
      return new Promise(resolve => {
        logout(state.token)
          .then(() => {
            commit("SET_TOKEN", "");
            commit("SET_ROLES", []);
            storage.remove(ACCESS_TOKEN);
            resetRouter();
            resolve();
          })
          .catch(() => {
            resolve();
          })
          .finally(() => {});
      });
    },
复制代码
文章分类
前端
文章标签