Hook into route change to hide the mobile menu

pull/12/head
cagataycivici 2018-12-26 12:39:12 +03:00
parent 5858f9cee3
commit f2df0ec2ee
2 changed files with 7 additions and 10 deletions

View File

@ -1,7 +1,7 @@
<template> <template>
<div class="layout-wrapper"> <div class="layout-wrapper">
<app-topbar @menubutton-click="onMenuButtonClick"/> <app-topbar @menubutton-click="onMenuButtonClick"/>
<app-menu :active="sidebarActive" @menuitem-click="onMenuItemClick" /> <app-menu :active="sidebarActive" />
<div :class="['layout-mask', {'layout-mask-active': sidebarActive}]" @click="onMaskClick"></div> <div :class="['layout-mask', {'layout-mask-active': sidebarActive}]" @click="onMaskClick"></div>
<div class="layout-content"> <div class="layout-content">
<router-view/> <router-view/>
@ -21,13 +21,15 @@ export default {
sidebarActive: false sidebarActive: false
} }
}, },
watch: {
$route() {
this.sidebarActive = false;
}
},
methods: { methods: {
onMenuButtonClick() { onMenuButtonClick() {
this.sidebarActive = !this.sidebarActive; this.sidebarActive = !this.sidebarActive;
}, },
onMenuItemClick(event) {
this.sidebarActive = false;
},
onMaskClick(event) { onMaskClick(event) {
this.sidebarActive = false; this.sidebarActive = false;
} }

View File

@ -1,5 +1,5 @@
<template> <template>
<div :class="['layout-sidebar', {'active': active}]" @click="onClick"> <div :class="['layout-sidebar', {'active': active}]">
<div class="layout-menu"> <div class="layout-menu">
<a @click="toggleMenu($event, 0)" :class="{'active-menuitem': activeMenuIndex === 0}"> <a @click="toggleMenu($event, 0)" :class="{'active-menuitem': activeMenuIndex === 0}">
<img alt="input" class="layout-menu-icon-inactive" src="./assets/images/menu/input.svg" /> <img alt="input" class="layout-menu-icon-inactive" src="./assets/images/menu/input.svg" />
@ -157,11 +157,6 @@ export default {
methods: { methods: {
toggleMenu(event, index) { toggleMenu(event, index) {
this.activeMenuIndex = (this.activeMenuIndex === index) ? null : index; this.activeMenuIndex = (this.activeMenuIndex === index) ? null : index;
},
onClick(event) {
if (event.target.nodeName === 'A') {
this.$emit('menuitem-click');
}
} }
} }
} }