diff --git a/src/layout/components/Sidebar/index.vue b/src/layout/components/Sidebar/index.vue index 04d8fb5..2110774 100644 --- a/src/layout/components/Sidebar/index.vue +++ b/src/layout/components/Sidebar/index.vue @@ -33,10 +33,11 @@ export default { components: { SidebarItem, Logo }, created: function () { this.getmunusdata(); + this.menusdatas = 66 }, data() { return { - routes:menusdata + //routes:this.menusdatas } }, computed: { @@ -67,43 +68,44 @@ export default { }, methods: { - SplicingMenuTree(menus, menusdatas) { - // console.log(menus); - // console.log(menusdatas); - // console.log(this.routes[0]); + SplicingMenuTree(menus) { + let newMenu = null, arrMenus = []; menus.forEach(item => { //console.log(menusdata[0]); - if (!menusdatas.children) { - this.$set(menusdatas,'children', []) - //menusdata[0].children = [] - } + // if (!this.menusdata.children) { + // this.$set(this.menusdata,'children', []) + // //menusdata[0].children = [] + // } - //Object.assign(menusdata[0],) - menusdatas.children.push( - { - path: '/subfile?id='+item.id, - meta: { title: item.directory, icon: 'dashboard' } - } - ); + newMenu = { + path: '/subfile?id='+item.id, + meta: { title: item.directory, icon: 'dashboard' }, + children:[] + } //console.log(item.directories.length); if (item.directories && item.directories.length > 0) { - this.SplicingMenuTree(item.directories, menusdatas.children[item.directories.length-1]) + newMenu.children = this.SplicingMenuTree(item.directories,) } + + arrMenus.push(newMenu); + console.log(arrMenus); + return arrMenus; }); - console.log(menusdata[0].children); + }, getmunusdata() { let thiss = this; - console.log(this.$route); - console.log(this.$store); + // console.log(this.$route); + // console.log(this.$store); mirlist().then(response => { let datamain = response.data; //routesData(datamain.data.menus); //console.log(response); - - this.SplicingMenuTree(datamain.data.menus, menusdata[0]); + console.log(this.menusdatas); + this.menusdatas = this.SplicingMenuTree(datamain.data.menus); + console.log(this.menusdatas); //this.routes = menusdata //console.log(menusdata); diff --git a/src/layout/components/Sidebar/leftMenusData.js b/src/layout/components/Sidebar/leftMenusData.js index 6f50e3a..6ef64c4 100644 --- a/src/layout/components/Sidebar/leftMenusData.js +++ b/src/layout/components/Sidebar/leftMenusData.js @@ -1,6 +1,6 @@ // 菜单栏生成 -let menusdata = [ +var menusdata = [ // { // id: '0',