代码优化 - 使用对象枚举,将switch语句优化

Before:

 switch (path) { 
        case "/options/store":
          return "store";
        case "/options/tiktok":
          return "tiktok";
        case "/options/kuaishou":
          return "kuaishou";
        case "/options/hamaqi":
          return "hamaqi";
}

 

After:

routerFilter () {
      const path = this.$route.path;
      const operators = {
        "/shareholder/basics": "basics",
        "/shareholder/setting": "setting",
      }; 
      return operators[path];
}

 

posted @ 2021-11-16 23:12  峻宇  阅读(101)  评论(0编辑  收藏  举报