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>

相关推荐
Anesthesia丶5 小时前
Vite + Svelte + shadcn-svelte 最小化 Demo+Vue3语法对比总结
vue·vite·svelte·shadcn-svelte
孟郎郎5 小时前
TimeoutError: The operation was aborted due to timeout at new DOMException
ai·前端框架·npm·vue·pnpm·deepseek
lpd_lt8 小时前
AI生成Spring Boot + Vue 3 + MySQL + MyBatis-Plus的项目实战
java·spring boot·vue·ai编程
来杯@Java17 小时前
图书管理系统(基于springboot+vue前后端分离的项目)计算机毕业设计java
java·spring boot·spring·vue·毕业设计·mybatis·课程设计
华大哥1 天前
前后端分离实现五级行政区划树形菜单及设备查询管理
sqlite·vue·springboot
码界筑梦坊1 天前
282-基于Python的豆瓣音乐可视化分析推荐系统
开发语言·python·信息可视化·数据分析·flask·vue
chushiyunen1 天前
滑块验证(滑动验证)
vue
Curvatureflight3 天前
前端国际化 i18n 落地实践:语言包、动态文案和格式化问题怎么处理?
前端·c++·vue
优雅格子衫3 天前
uniapp 拍照相册选取后超级好用的裁剪组件,增加水印完全自定义
开发语言·前端·javascript·uni-app·vue
路光.3 天前
uniapp中解决webview在app中调用,有过渡空白问题,增加过渡动效
uni-app·vue·app·uniapp