IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> JavaScript知识库 -> vue(四)vue3 + vite + routes 动态获取 -> 正文阅读

[JavaScript知识库]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 + '/' + obj.routePath
            result.push({
                path: obj.routePath,
                redirect: redirect + '/' + obj.redirect,
                children: getRouteObj(obj.children, redirect)
            })
        } else {
            result.push({
                path: obj.routePath,
                component: () => import('/src' + obj.codePath)
            })
        }
    }
    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}

  JavaScript知识库 最新文章
ES6的相关知识点
react 函数式组件 & react其他一些总结
Vue基础超详细
前端JS也可以连点成线(Vue中运用 AntVG6)
Vue事件处理的基本使用
Vue后台项目的记录 (一)
前后端分离vue跨域,devServer配置proxy代理
TypeScript
初识vuex
vue项目安装包指令收集
上一篇文章      下一篇文章      查看所有文章
加:2022-10-08 20:32:10  更:2022-10-08 20:33:38 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/17 17:38:40-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码