Skip to content

Instantly share code, notes, and snippets.

@chrfs
Last active January 21, 2018 14:36
Show Gist options
  • Save chrfs/ec74c402c982961b15e94d027dd662a1 to your computer and use it in GitHub Desktop.
Save chrfs/ec74c402c982961b15e94d027dd662a1 to your computer and use it in GitHub Desktop.
Generate header navigation with Vue-Router
<template>
<header id="header">
<ul id="header__nav--list">
<li v-for="(item, itemKey) in items" :key="itemKey"><router-link :to="item.path" exact>{{item.name}}</router-link></li>
</ul>
</header>
</template>
<script>
export default {
data() {
return {
items: []
};
},
created() {
this.$router.options.routes.forEach(route => {
this.items.push({
name: route.name,
path: route.path
});
});
}
};
</script>
<style lang="scss" scoped>
// Your styles here...
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment