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>

相关推荐
常宇佳2 天前
vue3 实战系列之踩过的一些坑
javascript·vue.js·elementui
宠友信息2 天前
IM系统开发技术路线分析,即时通讯源码助力快速搭建聊天应用
java·spring boot·redis·websocket·mysql·uni-app·vue
南城以南溫暖如初1474 天前
从传统健身房到无人值守:24小时自助健身系统的技术实现路径
java·spring boot·mysql·架构·vue
新中地GIS开发老师4 天前
WebGIS开发学生作品 | 基于无人机影像的烟草检测智能体与数字化管理平台
vue·web·mapbox·webgis
南城以南溫暖如初1474 天前
外卖CPS实战指南:从技术选型到运营落地全流程解析
java·spring boot·mysql·架构·vue
aXin_ya4 天前
ElementUI (01):Vue2 项目引入 ElementUI使用
elementui·vue
山川志~5 天前
Vue + Element UI 实战:如何实现表格时间、金额字段排序
vue.js·ui·elementui
常宇佳5 天前
vue3 @代指src路径设置
前端·typescript·vue
北城笑笑6 天前
Server 18 ,Nginx + Vite 前端部署排错实战:从 `/api/gpt/chat` 404 到 9012 后端服务的完整定位过程
linux·运维·前端·nginx·ubuntu·vue
小强库计算机毕业设计9 天前
SpringBoot+Vue3 学生宿舍管理系统实战
java·spring boot·后端·vue·学生宿舍管理系统