vue3 element-plus 将路由和激活菜单绑定

<template>
  <div class="sideBarPadding">
    <div>
      <SFMenu :default-active="activeMenu">
        <SFMenuItem
          v-for="item in personalDetailMenuList"
          :key="item.path"
          :index="item.path"
          @click="handleClickMenu(item.path)"
        >
          <ScIcon :name="item.meta.icon" class="icon-menu icon-menu-other" />
          <span>{
   {
    item.meta.title }}</span>
        </SFMenuItem>
      </SFMenu>
    </div>
  </div>
</template>
<script setup lang="ts">
import {
    onMounted, ref } from 'vue';
import {
    useRouter, useRoute } from 'vue-router';
const router = useRouter();
const activeMenu = ref<string>(''); //当前激活的菜单按钮
const personalDetailMenuList: any = [ //路由信息
  {
   
    path: '/login/personalInformation',
    name: 'personalData',
    component: () => import('@/views/PersonalInformation/components/personalInformation.vue'),
    // redirect: 'noRedirect',
    meta: {
   
      title: '个人资料',
      icon: 'icon-renyuanguanli',
    },
  },
  {
   
    path: '/login/accountSettings',
    name: 'accountSet',
    component: () => import('@/views/PersonalInformation/components/accountSettings.vue'),
    // redirect: 'noRedirect',
    meta: {
   
      title: '账号设置',
      icon: 'icon-shezhi',
    },
  },
];
// 点击菜单调整到相应页面
const handleClickMenu = (path: string) => {
   
  router.push(path);
};

// 挂载
onMounted(() => {
   
  const {
    path } = useRoute(); // 获取当前路径
  activeMenu.value = path; // 将当前路径和激活菜单绑定
});
</script>

相关推荐

  1. vue3 element-plus 激活菜单

    2023-12-07 16:20:09       39 阅读
  2. Crow:黑魔法 添加3 lambda

    2023-12-07 16:20:09       39 阅读

最近更新

  1. TCP协议是安全的吗?

    2023-12-07 16:20:09       19 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-07 16:20:09       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-07 16:20:09       20 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-07 16:20:09       20 阅读

热门阅读

  1. 传导电流密度方向与磁矢位方向相同

    2023-12-07 16:20:09       25 阅读
  2. 【FPGA图像处理实战】- 彩色图像灰度化

    2023-12-07 16:20:09       40 阅读
  3. TCP Socket API 讲解,以及回显服务器客户端的实现

    2023-12-07 16:20:09       24 阅读
  4. 关于在PyTorch中使用cudnn.benchmark= True

    2023-12-07 16:20:09       41 阅读
  5. 基于超声技术的气体流量测量仪设计

    2023-12-07 16:20:09       36 阅读
  6. Python 读取电子发票PDF 转成Excel

    2023-12-07 16:20:09       38 阅读
  7. 【Linux内核源码】进程管理模块

    2023-12-07 16:20:09       28 阅读
  8. 传纸条(算法题)

    2023-12-07 16:20:09       42 阅读