vue(四)vue3 + vite + routes 动态获取

阅读: 评论:0

vue(四)vue3 + vite + routes 动态获取

vue(四)vue3 + vite + routes 动态获取

作用:使用一份配置文件用于路由与菜单

版本说明:

"dependencies": {

    "element-plus": "^2.2.17",

    "vue": "^3.2.39",

    "vue-router": "^4.1.5"

  },

  "devDependencies": {

    "@vitejs/plugin-vue": "^3.1.0",

    "fast-glob": "^3.2.12",

    "vite": "^3.1.0",

    "vite-plugin-svg-icons": "^2.0.1"

  }

router_config.js

import { createRouter, createWebHistory } from 'vue-router'
import layout from '../layout/layout_index.vue'
import notFound from './public/not_found.vue'
import { menuConfig } from '../layout/menu_config.js'const routes = []
function getRouteObj(objArr, path) {const result = []if (!path) path = ''for (let t = 0; t < objArr.length; t++) {let obj = objArr[t]if (obj.children) {let redirect = path + '/' + utePathresult.push({path: utePath,redirect: redirect + '/' + direct,children: getRouteObj(obj.children, redirect)})} else {result.push({path: utePath,component: () => import('/src' + dePath)})}}return result
}routes.push({path: '/',component: layout,redirect: '/home',children: getRouteObj(menuConfig)
})
routes.push({path: '/:pathMatch(.*)*', name: 'NotFound', component: notFound
})const router = createRouter({history: createWebHistory(),routes
})export default router

menu_config.js

const menuConfig = [{/*** name 显示名称* routePath 路由在浏览器的url路径* icon svg图标* codePath 子页面文件路径* redirect 重定向,指向应该访问的子页面*/name:'Home',routePath: 'home',icon: 'caiselijia',redirect: 'status',children: [{name:'status',routePath: 'home',codePath: '/views/home.vue'},]},{name:'Interent',routePath: 'internet',icon: 'caisehuiyi',redirect: 'status',children: [{name:'Status',routePath: 'status',redirect: 'dsl',children: [{name:'DSL',routePath: 'dsl',codePath: '/views/internet/status/dsl.vue'},{name:'Ethernet',routePath: 'eth',codePath: '/views/internet/status/eth.vue'},{name:'3G',routePath: '3g',codePath: '/views/internet/status/3g.vue'},{name:'6RD',routePath: '6rd',codePath: '/views/internet/status/6rd.vue'}]},{name:'WAN',routePath: 'wan',codePath: '/views/internet/wan.vue'},{name:'QoS',routePath: 'qos',codePath: '/views/internet/qos.vue'},{name:'Security',routePath: 'security',codePath: '/views/internet/security.vue'}]},{name:'Local Network',routePath: 'network',icon: 'xiyiji',children: [{name:'Status',routePath: 'status',codePath: ''},{name:'WLAN',routePath: 'wlan',codePath: ''}]},{name:'VoIP',routePath: 'voip',icon: 'xiyiji',children: [{name:'Status',routePath: 'status',codePath: ''},{name:'Basic',routePath: 'wlan',codePath: ''}]},{name:'Management & Diagnosis',routePath: 'management',icon: 'yizi',children: [{name:'Status',routePath: 'status',codePath: ''},{name:'Account Management',routePath: 'account',codePath: ''}]},
]export {menuConfig}

本文发布于:2024-01-30 18:15:01,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170660970321897.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:动态   vue   routes   vite
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23