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>

相关推荐
骑着蜗牛撵大象32716 小时前
SpringBoot+Vue3 企业智能体侧挂架构:独立服务、独立数据库与主线零侵入落地
数据库·spring boot·架构·vue·springboot·事件驱动·服务拆分
码艺-Alimjan3 天前
Tauri 网站To桌面应用实战总结
前端·javascript·vue
雪芽蓝域zzs5 天前
第7节:多选模式、自定义选项渲染、受控弹窗显隐
vue.js·elementui
liangshiwei5 天前
ABP x Vue:介绍 ABP Vue UI
vue·abp
雪芽蓝域zzs6 天前
第6节:远程搜索弹窗(remote 模式),弹窗滚动加载分页
vue.js·elementui
雪芽蓝域zzs6 天前
第4节:el-select 弹窗事件控制(打开 / 关闭、选中事件、弹窗滚动事件)
vue.js·elementui
frjc7 天前
前端技术选型:主流方案对比与落地建议
vue·react·angular
ss2737 天前
AI全栈实战 | 2.3-01 组件库实战:Element Plus 怎么搭出专业界面,过度封装为什么成维护负担
前端·javascript·elementui·vue
雪芽蓝域zzs7 天前
第3节:el-select 弹窗定位、滚动穿透与挂载容器(popper-append-to-body /teleported)
vue.js·elementui
雪芽蓝域zzs7 天前
第 2 节:基础扩展 - 下拉弹窗常用原生属性
vue.js·elementui