王旭
2022-10-13 6ba67905ae3e502103a940f5f6f907e8f491ae62
src/components/navMenu.vue
@@ -67,7 +67,20 @@
  mounted() {
    this.getMenuTree();
  },
  computed: {},
  computed: {
    // 我们使用计算属性来获取到当前点击的菜单的路由路径,然后设置default-active中的值
    // 使得菜单在载入时就能对应高亮
    // activeIndex() {
    //   const route = this.$route;
    //   const { meta, path } = route;
    //   // if set path, the sidebar will highlight the path you set
    //   // 可以在路由配置文件中设置自定义的路由路径到meta.activeMenu属性中,来控制菜单自定义高亮显示
    //   if (meta.activeMenu) {
    //     return meta.activeMenu;
    //   }
    //   return path;
    // },
  },
  methods: {
    getMenuTree() {
      //获取目录树最大ID,新建节点使用
@@ -160,9 +173,18 @@
  },
  watch: {
    $route() {
      this.activeIndex = this.$route.path;
      let str = this.$route.path;
      if (str[0] == "/") {
        this.activeIndex = str.slice(1);
      }
    },
  },
  created() {
    let str = this.$route.path;
    if (str[0] == "/") {
      this.activeIndex = str.slice(1);
    }
  },
};
</script>
<style lang="less" scoped>