<template>
<!--实现左侧导航条动态渲染(三级)-->
<el-menu class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose" :collapse="isCollapse" router unique-opened
background-color="#545c64"
text-color="#fff"
active-text-color="#ffd04b">

<el-menu-item index="/home/main">
<i class="el-icon-document"></i>
<span slot="title">首页</span>
</el-menu-item>

<el-submenu v-for="(item,index) in content" :key="item.id" :data="item" v-if="item.children.length>0&&item.level==1" :index="item.linkname">
<template slot="title">
<i class="el-icon-location"></i>
<span slot="title">{{item.linkname}}</span>
</template>

<el-submenu v-for="(child,seq) in item.children" :data="child" v-if="item.id==child.parentid&&child.children.length>0&&child.level==2" :key="child.id" :index="child.linkname">
<span slot="title">{{child.linkname}}</span>

<el-menu-item v-for="three in child.children" :data="three" v-if="child.id==three.parentid&&child.children.length!=0&&three.level==3" :key="three.id" :index="three.link">
<span slot="title">{{three.linkname}}</span>
</el-menu-item>

</el-submenu>

<!--2无子级显示-->
<el-menu-item v-for="(child,seq) in item.children" :data="child" v-if="item.id==child.parentid&&child.children.length==0&&child.level==2" :key="child.id" :index="child.link">
<span slot="title">{{child.linkname}}</span>
</el-menu-item>

</el-submenu>

<!--1无子级显示且不支持点击事件-->
<el-menu-item v-for="(item,index) in content" :key="item.id" :data="item" v-if="item.children.length==0&&item.level==1" :index="item.linkname" :disabled="item.children.length==0 ? true : false ">
<i class="el-icon-setting"></i>
<span slot="title">{{item.linkname}}</span>
</el-menu-item>
</el-menu>

</div>
</template>

<script>
import axios from "axios";
import $ from 'jquery';

export default {
data() {
return {
content: [],
isCollapse: false,
defaultProps: {
children: 'children',
label: 'linkname'
}
};
},
mounted(){
var _self = this;
axios.get('https://5b90a18b3ef10a001445d08e.mockapi.io/api/v1/resources')
.then(function (response) {
_self.content = returnZhData(response.data);
})
.catch(function (error) {
console.log(error);
});
},
methods: {
handleOpen(key, keyPath) {
console.log(key, keyPath);
},
handleClose(key, keyPath) {
console.log(key, keyPath);
},
handleNodeClick(content) {
console.log(content);
}
}
}
function returnZhData(data){
var arrone=[];
$.each(data, function(index,one) {
if(one['level'] == 1){
arrone.push(one);

var arrtwo=[];
$.each(data, function(index,two) {

if(two['level'] == 2 && two['parentid']==one['id']){
arrtwo.push(two);


var arrthree=[];
$.each(data, function(index,three) {
if(three['level'] == 3 && three['parentid']==two['id']){
arrthree.push(three);
}
});
two.children=arrthree;
}

});

one.children = arrtwo;
}
});
return arrone;
}
</script>

<style>
.el-menu-vertical-demo:not(.el-menu--collapse) {
width: auto;
min-height: 400px;
}
</style>

vue Element-ui el-menu 左侧导航条的更多相关文章

  1. Vue+Element UI 实现视频上传

    一.前言 项目中需要提供一个视频介绍,使用户能够快速.方便的了解如何使用产品以及注意事项. 前台使用Vue+Element UI中的el-upload组件实现视频上传及进度条展示,后台提供视频上传AP ...

  2. vue + element ui 实现实现动态渲染表格

    前言:之前需要做一个页面,能够通过表名动态渲染出不同的表格,这里记录一下.转载请注明出处:https://www.cnblogs.com/yuxiaole/p/9786326.html 网站地址:我的 ...

  3. vue + element ui 表格自定义表头,提供线上demo

    前言:工作中用到 vue+element ui 的前端框架,需要使用自定义表头,需要使用 re.转载请注明出处:https://www.cnblogs.com/yuxiaole/p/9710826.h ...

  4. vue+element ui 的表格列使用组件

    前言:工作中用到 vue+element ui 的前端框架,有这个场景:很多表格的列有许多一样的,所以考虑将列封装为组件.转载请注明出处:https://www.cnblogs.com/yuxiaol ...

  5. vue+element ui 的tab 动态增减,切换时提示用户是否切换

    前言:工作中用到 vue+element ui 的前端框架,动态添加 Tab,删除 Tab,切换 Tab 时提示用户是否切换等,发现 element ui  有一个 bug,这里记录一下如何实现.转载 ...

  6. vue + element ui 阻止表单输入框回车刷新页面

    问题 在 vue+element ui 中只有一个输入框(el-input)的情况下,回车会提交表单. 解决方案 在 el-form 上加上 @submit.native.prevent 这个则会阻止 ...

  7. vue+element ui 的时间控件选择 年月日时分

    前言:工作中用到 vue+element ui 的前端框架,需要选择年月日时分,但element ui官网demo有没有,所以记录一下.转载请注明出处:https://www.cnblogs.com/ ...

  8. Vue+element ui table 导出到excel

    需求: Vue+element UI table下的根据搜索条件导出当前所有数据 参考: https://blog.csdn.net/u010427666/article/details/792081 ...

  9. 分享一个自搭的框架,使用Spring boot+Vue+Element UI

    废弃,新的:https://www.cnblogs.com/hackyo/p/10453243.html 特点:前后端分离,可遵循restful 框架:后端使用Spring boot,整合了aop.a ...

随机推荐

  1. JavaScript事件绑定的三种方式

    (一)事件绑定的三种方式 (1)通过on的形式 <script type="text/javascript"> var div = document.getElemen ...

  2. spring-cloud-sleuth/zipkin

    Spring Cloud Sleuth 一般的,一个分布式服务跟踪系统,主要有三部分:数据收集.数据存储和数据展示.根据系统大小不同,每一部分的结构又有一定变化.譬如,对于大规模分布式系统,数据存储可 ...

  3. Java开发工程师最新面试题库系列——集合部分(附答案)

    集合 如果你有更好的想法请在评论区留下您的答案,一起交流讨论 说说常见的集合有哪些? 答:主要分List.Set.Map.Queue四类,其中包含ArrayList.LinkedList.HashSe ...

  4. Steam 钓鱼模拟器

    Steam 钓鱼模拟器 Fishing Planet Fishing Planet 是一个独特和高度现实的在线第一人称多人钓鱼模拟器,由狂热的钓鱼爱好者钓鱼给你带来实际钓鱼充分刺激开发! 选择你的诱饵 ...

  5. 微信公众号 webfullstack

    微信公众号 webfullstack weixin refs https://mp.weixin.qq.com/cgi-bin/loginpage?t=wxm2-login&lang=zh_C ...

  6. js types & primitive & object

    js types & primitive & object js 数据类型 typeof null // "object" typeof undefined // ...

  7. webpack & chunkhash

    webpack & chunkhash https://webpack.js.org/configuration/output/#outputchunkfilename https://web ...

  8. js assert

    js assert console.assert The console.assert() method writes an error message to the console if the a ...

  9. sql server 局域网与公网上的发布与订阅

    一台局域网的服务器,可以访问公网. 一台云端的服务器. 要求:将局域网中的服务器部分数据库同步到云端的服务器上. 配置情况: win server 2012 是发布服务器. win server 20 ...

  10. 自定义Edit 样式 简便写法

    1 <?xml version="1.0" encoding="utf-8"?> 2 <selector xmlns:android=&quo ...