el-menu 导航栏学习(1)

最简单的导航栏学习跳转实例效果:

(1)index.js路由配置:

import Vue from 'vue'

import Router from 'vue-router'

import NavMenuDemo from '@/components/NavMenuDemo'

import test1 from '@/components/test1'

import test2 from '@/components/test2'

import test3 from '@/components/test3'

Vue.use(Router)

export default new Router({

routes: [{

path: '/',

name: 'NavMenuDemo',

component: NavMenuDemo,

children: [{

path: '/test1',

name: 'test1',

component: test1

}, {

path: '/test2',

name: 'test2',

component: test2

}, {

path: '/test3',

name: 'test3',

component: test3

},]

}]

})

(2)NavMenuDemo.vue

<template>

<el-container>

<el-aside width="200px">

<el-menu

default-active="1"

class="el-menu-vertical-demo"

router

>

<el-menu-item index="/test1"

@click="$router.push({ path: '/test1' })"

>

<i class="el-icon-menu"></i>

<span slot="title">导航二</span>

</el-menu-item>

<el-menu-item index="/test2"

@click="$router.push({ path: '/test2' })"

>

<i class="el-icon-document"></i>

<span slot="title">导航三</span>

</el-menu-item>

<el-menu-item index="/test3"

@click="$router.push({ path: '/test3' })"

>

<i class="el-icon-setting"></i>

<span slot="title">导航四</span>

</el-menu-item>

</el-menu>

</el-aside>

<el-main>

<router-view></router-view>

</el-main>

</el-container>

</template>

<style>

.el-aside {

height: 100vh;

text-align: center;

}

.el-main {

background-color: #E9EEF3;

}

</style>

(3)test1.vue

<template>

<p>1</p>

</template>

(4)test2.vue

<template>

<p>2</p>

</template>

最简单的导航栏配置如上图所示,项目中的文件结构如下所示

相关推荐
汤米粥12 小时前
2026年主流前端技术框架
vue·react·elementplus·tailwind css·angular‌·svelte‌·bootstrap‌
codigger17 小时前
Vue nextTick 到底在等什么?一篇讲透原理与那些年踩过的坑
程序员·vue·编程·异步更新·#人工智能
咚咚咚小柒1 天前
【前端】LangChain.js学习
前端·javascript·人工智能·typescript·langchain·vue·ai编程
悟道书生4 天前
若依 RBAC 权限控制学习笔记
java·网络·笔记·sql·学习·vue
mewowaBc4 天前
使用Pinia持久化存储实现用户认证系统
vue·pinia·用户认证系统
gc_22994 天前
使用VS Code终端创建Vue项目报错:“npm : 无法加载文件 ...\npm.ps1,因为在此系统上禁止运行脚本”
vue·vs code
小阿鑫5 天前
尤雨溪 : Vue 4 已经在规划中了!
vue·vite·vite+·程序员海军·vue4
离歌漠5 天前
《我用 Tauri 做了一个本地开发工具箱》
rust·typescript·vue
enjoy编程6 天前
playwright学习-I
typescript·vue·nodejs·1024程序员节·playwright
落花看风雪8 天前
从零开始搭建后台系统(vue3+TypeScript+Vite)01
typescript·vue·js