vue:路由配置 meta 的 menu 和 icon

本文介绍如何使用AntdVue UI库结合Vue Router实现菜单的动态加载和路由配置。通过计算属性获取路由信息,展示一级和二级菜单,包括菜单标题和图标。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

首先,我引用的是antd vue 的这套UI。

可以在 computed 中打印出 this.$router 下面的东西,是获取的路由中配置的菜单和 icon。

代码图和代码请看下面文件配置

menu.js 文件配置后代码如下:

首先,我引用的是antd vue 的这套UI。

 

可以在 computed 中打印出 this.$router 下面的东西,是获取的路由中配置的菜单和 icon。

 

代码图和代码请看下面文件配置

 

menu.js 文件配置后代码如下:

 

 

<template>

    <div class="menu">

      <a-menu v-model="current" mode="inline" theme="dark">

          <template v-for='route in routes'>

              <!-- 一级菜单 -->

              <a-menu-item v-if='route.children && route.children.length == 1' :key='route.path'>

                <router-link :to='route.path'>

                    <a-icon :type='route.meta.icon' />

                    {{ route.meta.title }}

                </router-link>

              </a-menu-item>

 

              <!-- 二级菜单 -->

              <a-sub-menu v-else='route.children && route.children.length == 2' key="sub1">

                <span slot="title"><span><a-icon :type='route.meta.icon' />{{ route.meta.title}}</span></span>

                <a-menu-item v-for='item in route.children' :key='item.path'>

                    <!-- <router-link :to='resolve(route.path,item.path)'> -->

                    <router-link :to="`${route.path}/${item.path}`">

                        <a-icon :type='item.meta.icon' />

                        {{ item.meta.title }}

                    </router-link>

                </a-menu-item>

              </a-sub-menu>

          </template>

      </a-menu>

    </div>

</template>

 

<script>

 

export default {

    name: 'Menu',

    data() {

      return {

          current: ['/'],

      }

    },

    computed: { // 计算属性:获取路由

        routes() {

            console.log('test', this.$router)

            console.log('ddd', this.$router.options.routes)

            return this.$router.options.routes

        },

    },

    methods:{

        resolve(p,i){

          return `${p}/${i}`

        },

    },

}

</script>

Router.js 文件配置:

 

import Vue from 'vue';

import Router from 'vue-router';

import HelloWorld from '@/components/HelloWorld';

Vue.use(Router);

 

// 引入的页面布局(头、菜单、内容、底部)

// import Layout from '../layout/index.vue';

import Layout from '@/layout';

 

export default new Router({

  routes: [

      {

          path: '/',

          component: Layout,

          meta: { title: '首页', icon: 'home'}, // 路由元:{ 标题,icon 图标 }

          children: [{

                path: '/',

                component: () => import( "@/views/Home.vue"),

          }]

      },

      {

        path: '/basic',

        component: Layout,

        meta: { title: '基础', icon: 'desktop' },

        children: [

            {

                path: 'helloworld',

                component: HelloWorld,

                meta: { title: '链接', icon: 'link' }

            },

            {

                path: 'instruction',

                component: () => import('@/views/Instruction.vue'),

                meta: { title: '指令', icon: 'code' }

            },

            {

                path: 'cycle',

                component: () => import('@/views/Cycle.vue'),

                meta: { title: '钩子函数', icon: 'heart' }

            }

        ]

    },

    {

        path: '/echart',

        component: Layout,

        meta: { title: 'Echart',icon: 'bar-chart' },

        children: [{

          path: '/echart',

          component: () => import( "@/views/Echart.vue"),

        }]

    },

    {

        path: '/table',

        component: Layout,

        meta: { title: 'Table', icon: 'table' },

        children: [{

          path: '/table',

          component: () => import( "@/views/Table.vue"),

        }]

    },

  ]

})

 

 

 

Router.js 文件配置:

 

 

import Vue from 'vue';

import Router from 'vue-router';

import HelloWorld from '@/components/HelloWorld';

Vue.use(Router);

 

// 引入的页面布局(头、菜单、内容、底部)

// import Layout from '../layout/index.vue';

import Layout from '@/layout';

 

export default new Router({

  routes: [

      {

          path: '/',

          component: Layout,

          meta: { title: '首页', icon: 'home'}, // 路由元:{ 标题,icon 图标 }

          children: [{

                path: '/',

                component: () => import( "@/views/Home.vue"),

          }]

      },

      {

        path: '/basic',

        component: Layout,

        meta: { title: '基础', icon: 'desktop' },

        children: [

            {

                path: 'helloworld',

                component: HelloWorld,

                meta: { title: '链接', icon: 'link' }

            },

            {

                path: 'instruction',

                component: () => import('@/views/Instruction.vue'),

                meta: { title: '指令', icon: 'code' }

            },

            {

                path: 'cycle',

                component: () => import('@/views/Cycle.vue'),

                meta: { title: '钩子函数', icon: 'heart' }

            }

        ]

    },

    {

        path: '/echart',

        component: Layout,

        meta: { title: 'Echart',icon: 'bar-chart' },

        children: [{

          path: '/echart',

          component: () => import( "@/views/Echart.vue"),

        }]

    },

    {

        path: '/table',

        component: Layout,

        meta: { title: 'Table', icon: 'table' },

        children: [{

          path: '/table',

          component: () => import( "@/views/Table.vue"),

        }]

    },

  ]

})

 

 

使用Vue3+TypeScript 设计一个登录页面(账号密码)实现单点登录并集成微软登录认证(先向微软认证,再向后端(nestjs)请求人员角色信息,然后页面跳转flow页面 ,需要在路由配置角色权限管控 现在的路由const routes = [ { path: ‘/’, redirect: ‘/flow’, component: () => import(‘@/layout/MainLayout.vue’), children: [ { path: ‘/flow’, name: ‘flow’, component: () => import(‘@/views/ProcessFlow.vue’), meta: { isShow: true, title: ‘Flow’, icon:Menu’ } }, { path: ‘/viewList’, name: ‘viewList’, meta: { isShow: true, title: ‘OverView’, icon: ‘List’ }, children: [ { path: ‘/viewList/ocrList’, name: ‘ocrList’, component: () => import(‘@/views/OCRDecView.vue’), meta: { title: ‘OCR’, icon: ‘Filter’ } }, { path: ‘/viewList/orderDetails’, name: ‘orderDetails’, component: () => import(‘@/views/MaterialOrderDetailsView.vue’), meta: { title: ‘OrderDetails’, icon: ‘Filter’ } } ] }, { path: ‘/config’, name: ‘config’, meta: { isShow: true, title: ‘Config’, icon: ‘Setting’ }, children: [ { path: ‘/config/users’, name: ‘userConfig’, component: () => import(‘@/views/UserManagement.vue’), meta: { title: ‘Users’, icon: ‘User’ } }, { path: ‘/config/materialBase’, name: ‘materialBase’, component: () => import(‘@/views/MaterialBase.vue’), meta: { title: ‘Materials’, icon: ‘Plus’ } }, { path: ‘/config/materialOrder’, name: ‘materialOrder’, component: () => import(‘@/views/MaterialOrder.vue’), meta: { title: ‘Orders’, icon: ‘Plus’ } }, { path: ‘/config/materialFormat’, name: ‘materialFormat’, component: () => import(‘@/views/MaterialFormat.vue’), meta: { title: ‘Formats’, icon: ‘Brush’ } } ] } ] } ]
最新发布
08-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值