el-menu 导航栏学习-for循环封装(2)

基于el-menu 导航栏学习(1)

对于导航栏主菜单NavMenuDemo.vue进行for循环改进,代码如下所示:

<template>

<el-container>

<el-aside width="200px">

<el-menu

:default-active="this.$route.path"

class="el-menu-demo"

router

@select="handleSelect"

>

<el-menu-item v-for="(item, i) in navList" :key="i" :index="item.name">

<template slot="title">

<i class="el-icon-s-platform"></i>

<span> {{ item.navItem }}</span>

</template>

</el-menu-item>

</el-menu>

</el-aside>

<el-main>

<router-view></router-view>

</el-main>

</el-container>

</template>

<script>

export default({

data() {

return {

navList: [

{ name: "/test1", navItem: "导航一" },

{ name: "/test2", navItem: "导航二" },

{ name: "/test3", navItem: "导航三" },

],

};

},

methods:{

handleSelect(key, keyPath) {

console.log(key, keyPath);

},

}

})

</script>

<style>

.el-aside {

height: 100vh;

text-align: center;

}

.el-main {

background-color: #E9EEF3;

}

</style>

相关推荐
RichardLau_Cx1 小时前
【保姆级实操】MediaPipe SDK/API 前端项目接入指南(Web版,可直接复制代码)
前端·vue·react·webassembly·mediapipe·手部追踪·前端计算机视觉
chao_7897 小时前
双设备全栈开发最佳实践[mac系统]
git·python·macos·docker·vue·全栈
码农幻想梦7 小时前
Vue3入门到实战【尚硅谷】
前端·vue
吃茄子的猫7 小时前
若依框架根据当前登录人信息,显示不同的静态公司logo
前端·vue
Hexene...8 小时前
【前端Vue】出现elementui的index.css引入报错如何解决?
前端·javascript·vue.js·elementui
千寻技术帮1 天前
10386_基于SpringBoot的外卖点餐管理系统
java·spring boot·vue·外卖点餐
东东5163 天前
xxx医患档案管理系统
java·spring boot·vue·毕业设计·智慧城市
码界奇点3 天前
基于Spring Boot和Vue3的无头内容管理系统设计与实现
java·spring boot·后端·vue·毕业设计·源代码管理
东东5163 天前
基于Web的智慧城市实验室系统设计与实现vue + ssm
java·前端·人工智能·后端·vue·毕业设计·智慧城市
小小弯_Shelby3 天前
el-table固定列显示错位问题处理
vue.js·elementui