Skip to content

Instantly share code, notes, and snippets.

@pratheekhegde
Last active February 19, 2018 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pratheekhegde/e420bfb3cc00122f261792c84025da67 to your computer and use it in GitHub Desktop.
Save pratheekhegde/e420bfb3cc00122f261792c84025da67 to your computer and use it in GitHub Desktop.
Vue BreadCrumb component
<template>
<div>
{{ crumbs }} // printing raw json
<br><br>
<div class="container">
<b-breadcrumb :items="crumbs"/>
</div>
</div>
</template>
<script>
export default {
computed: {
crumbs: function() {
let pathArray = this.$route.path.split("/")
pathArray.shift()
let breadcrumbs = pathArray.reduce((breadcrumbArray, path, idx) => {
breadcrumbArray.push({
path: path,
to: breadcrumbArray[idx - 1]
? "/" + breadcrumbArray[idx - 1].path + "/" + path
: "/" + path,
text: this.$route.matched[idx].meta.breadCrumb || path,
});
return breadcrumbArray;
}, [])
return breadcrumbs;
}
}
};
</script>
<style scoped>
.container{
margin: auto;
width: 50%
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment