首页 >> 大全

element ui菜单栏动态渲染

2023-09-05 大全 33 作者:考证青年

直接上代码,模块清晰,自己赋值粘贴都行

<el-menu :default-active="this.$route.path":unique-opened="true"routerclass="el-menu-vertical-demo"background-color="#393e46"text-color="#fff"active-text-color="#4480e9"style="height: 100%;border-right: solid 0px #e6e6e6;width:150px"background-color="#393e46" text-color="#fff" active-text-color="#ffd04b" :collapse="getMenuSwitchState"><!--单级菜单--><el-menu-item :index="item.path" v-for="item in noChildren" :key="item.path"><i :class="'el-icon-' + item.icon"></i><span slot="title">{{item.label}}</span></el-menu-item>	<!--多级菜单--><el-submenu :index=index.toString() v-for="(item,index) in hasChildren" :key="index"><template slot="title"><i class="el-icon-menu"></i><span>{{item.label}}</span> </template><el-menu-item-group><el-menu-item :index="subItem.path" v-for="(subItem,subIndex) in item.children" :key="subIndex">{{subItem.label}}</el-menu-item></el-menu-item-group></el-submenu>
</el-menu>

解决某哥们的 :-=“true” 失效问题

vue动态渲染菜单_动态渲染组件_

建议一级菜单的话,后台就不要返回 [] 了,直接去掉,不然 会默认当成二级处理,除非自己把数据处理下,前端处理的话,初始渲染速度可能会受影响。

 computed: {noChildren() {return this.asideMenu.filter(item =>!item.children)},hasChildren() {return this.asideMenu.filter(item =>item.children)}
}

asideMenu: [{path: '/', //地址label: '首页', // 菜单标识icon: 's-home', //图标选取的是element图表,然后拼接到上面},{path: "/video",label: '视频管理',icon: 'video-play'},{path: "/user",label: '用户管理',icon: 'user'},//二级菜单{label: '多级菜单',icon: 'user',children: [{path: "/page1",label: '页面1',icon: 'setting'},{path: "/page2",label: '页面1',icon: 'user'},]},
]

动态渲染组件_vue动态渲染菜单_

created(){
//登录返回  
//  localStorage.setItem('asideMenu', JSON.stringify(返回的数组))  localStorage默认只能存字符串,所以转下
this.asideMenu = JSON.parse(localStorage.getItem('asideMenu'))  //取出赋值给变量
// console.log(JSON.parse(localStorage.getItem('asideMenu')))}

借用某哥们的效果图一用

关于我们

最火推荐

小编推荐

联系我们


版权声明:本站内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 88@qq.com 举报,一经查实,本站将立刻删除。备案号:桂ICP备2021009421号
Powered By Z-BlogPHP.
复制成功
微信号:
我知道了