<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. 4.Direct交换机之使用指定routingkey完成日志记录场景

    标题 : 4.Direct交换机之使用指定routingkey完成日志记录场景 目录 : RabbitMQ 序号 : 4 const string logOthersQueueName = " ...

  2. cookie,session,token之间的联系与区别

    发展史 1.很久很久以前,Web 基本上就是文档的浏览而已, 既然是浏览,作为服务器, 不需要记录谁在某一段时间里都浏览了什么文档,每次请求都是一个新的HTTP协议, 就是请求加响应,  尤其是我不用 ...

  3. 12.tomcat7切换tomcat8导致cookie异常

    一.现象 换成Tomcat8后出现cookie报错 二.分析 经异常去查看源码发现,Tomcat8对cookie校验规则改变,更为严格的校验了cookieHeader不允许有, 日志中的[XXXXX, ...

  4. Mybatis-02 CRUD

    Mybatis-02 CRUD CRUD 先来简单回顾一下之前的准备步骤: 创建一个数据库,并加入数据 创建一个Maven项目 导入对应的依赖 创建Pojo类和Dao类 写出Mybatis工具类 配置 ...

  5. HTML5 动画效果的多种实现方式

    HTML5 动画效果的多种实现方式 1.  CSS3 transform + transition https://www.w3.org/TR/css-transforms-1/ https://ww ...

  6. 使用 js 实现一个简易版的模版引擎

    使用 js 实现一个简易版的模版引擎 regex (function test() { this.str = str; })( window.Test = ...; format() { let ar ...

  7. PWA & Service Workers 版本更新 bug

    PWA & Service Workers 版本更新 bug PWA & Service Worker https://developer.mozilla.org/zh-CN/docs ...

  8. js 实现前端路由的方法

    js 实现前端路由的方法 前端路由原理 History API https://developer.mozilla.org/en-US/docs/Web/API/History_API https:/ ...

  9. qt 注册热键

    原文 将所需的库添加到您的qmake项目(.PRO文件) LIBS += \ -lUser32 2.在代码中包含所需的头文件. #include <windows.h> 在程序开始时注册热 ...

  10. Dart 中断Future

    更多 中断future 方法1) import 'package:async/async.dart'; void main() { var get = CancelableOperation.from ...