Skip to content

Commit

Permalink
Close Burger When Change Route
Browse files Browse the repository at this point in the history
  • Loading branch information
berviantoleo committed Nov 27, 2018
1 parent e62aa38 commit 8ac5148
Showing 1 changed file with 46 additions and 29 deletions.
75 changes: 46 additions & 29 deletions src/components/MyHeader.vue
Original file line number Diff line number Diff line change
@@ -1,38 +1,55 @@
<template>
<nav class="navbar is-fixed-top" role="navigation" aria-label="main navigation">
<div class="navbar-brand">
<router-link class="navbar-item" to="/"><img src="../assets/logo.png" width="112" height="28"></router-link>
<a
id="burger"
role="button"
class="navbar-burger burger"
aria-label="menu"
aria-expanded="false"
data-target="navbarBasicExample"
@click="burgerClick"
>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
</a>
</div>
<div id="navbarBasicExample" class="navbar-menu">
<div class="navbar-end">
<router-link class="navbar-item" to="/">Home</router-link>
<router-link class="navbar-item" to="/education">Education</router-link>
<router-link class="navbar-item" to="/experience">Experience</router-link>
<router-link class="navbar-item" to="/portofolio">Portofolio</router-link>
<router-link class="navbar-item" to="/about">About</router-link>
</div>
</div>
</nav>
<nav class="navbar is-fixed-top" role="navigation" aria-label="main navigation">
<div class="navbar-brand">
<router-link class="navbar-item" to="/">
<img src="../assets/logo.png" width="112" height="28">
</router-link>
<a
id="burger"
role="button"
class="navbar-burger burger"
aria-label="menu"
aria-expanded="false"
data-target="navbarBasicExample"
@click="burgerClick"
>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
</a>
</div>
<div id="navbarBasicExample" class="navbar-menu">
<div class="navbar-end">
<router-link class="navbar-item" to="/">Home</router-link>
<router-link class="navbar-item" to="/education">Education</router-link>
<router-link class="navbar-item" to="/experience">Experience</router-link>
<router-link class="navbar-item" to="/portofolio">Portofolio</router-link>
<router-link class="navbar-item" to="/about">About</router-link>
</div>
</div>
</nav>
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
<script lang="ts" scoped>
import { Component, Vue, Watch } from 'vue-property-decorator'
@Component
export default class MyHeader extends Vue {
@Watch('$route')
public closeBurger(): void {
const burger = document.getElementById('burger')
if (burger) {
burger.classList.remove('is-active')
const target = burger.dataset.target
if (target) {
const $target = document.getElementById(target)
if ($target) {
$target.classList.remove('is-active')
}
}
}
}
public burgerClick(): void {
const burger = document.getElementById('burger')
if (burger) {
Expand Down

0 comments on commit 8ac5148

Please sign in to comment.