Former-commit-id: a028cd2bfb5d361eeb019eafc1203d26fd68a35e
This commit is contained in:
FairyEver
2019-08-11 00:11:13 +08:00
parent 1ae45c5f62
commit ac906425c0
3 changed files with 25 additions and 16 deletions
@@ -1,8 +1,6 @@
import { uniqueId } from 'lodash'
// 创建 el-menu-item
export function elMenuItem (createElement, menu) {
return createElement('el-menu-item', { props: { index: menu.path || uniqueId('d2-menu-empty-') } }, [
return createElement('el-menu-item', { props: { index: menu.path } }, [
...menu.icon ? [
createElement('i', { attrs: { class: `fa fa-${menu.icon}` } })
] : [],
@@ -12,13 +10,13 @@ export function elMenuItem (createElement, menu) {
...menu.iconSvg ? [
createElement('d2-icon-svg', { props: { name: menu.iconSvg } })
] : [],
createElement('span', { slot: 'title' }, menu.title || '未命名菜单')
createElement('span', { slot: 'title' }, menu.title || this.$t('layout.header-aside.menu-item.label-default'))
])
}
// 创建 el-submenu
export function elSubmenu (createElement, menu) {
return createElement('el-submenu', { props: { index: menu.path || uniqueId('d2-menu-empty-') } }, [
return createElement('el-submenu', { props: { index: menu.path } }, [
...menu.icon ? [
createElement('i', { slot: 'title', attrs: { class: `fa fa-${menu.icon}` } })
] : [],
@@ -28,7 +26,7 @@ export function elSubmenu (createElement, menu) {
...menu.iconSvg ? [
createElement('d2-icon-svg', { slot: 'title', props: { name: menu.iconSvg } })
] : [],
createElement('span', { slot: 'title' }, menu.title || '未命名菜单'),
createElement('span', { slot: 'title' }, menu.title || this.$t('layout.header-aside.menu-item.label-default')),
...menu.children.map((child, childIndex) => (child.children === undefined ? elMenuItem : elSubmenu).call(this, createElement, child))
])
}
@@ -45,14 +45,9 @@ export default {
}, 500)
},
// 监听路由 控制侧边栏激活状态
'$route': {
handler ({ fullPath }) {
this.active = fullPath
this.$nextTick(() => {
if (this.aside.length > 0 && this.$refs.menu) {
this.$refs.menu.activeIndex = fullPath
}
})
'$route.fullPath': {
handler (value) {
this.active = value
},
immediate: true
}