Last active
January 21, 2018 14:36
-
-
Save chrfs/ec74c402c982961b15e94d027dd662a1 to your computer and use it in GitHub Desktop.
Generate header navigation with Vue-Router
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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