Dynamic breadcrumbs in Vue JS

Today, We want to share with you Dynamic breadcrumbs in Vue JS.In this post we will show you Displaying application Breadcrumbs in Vue.js, hear for Creating a breadcrumb from the current path – Vue.js 2.x by Example we will give you demo and example for implement.In this post, we will learn about Handling breadcrumbs with VueX in a VueJS Single Page Application with an example.

Dynamic breadcrumbs in Vue JS

There are the Following The simple About Dynamic breadcrumbs in Vue JS Full Information With Example and source code.

As I will cover this Post with live Working example to develop Dynamic Breadcrumbs with vuex2 & vue-router 2, so vuetify breadcrumbs vue router for this example is following below.

Automated Breadcrumbs with VueJS

Step 1: Vuejs Part

const state = {
  products: [{id: 12, name: "Iphone"},{id: 13, name: "Mobile"}],
  activeProductId: null,
}
const mutations = {
  setActiveProduct: (state, payload) => {
    state.activeProductId = payload.id
  }
}
const getters = {
  activeProduct: ({products, activeProductId}) => {
    return products.find((u) => u.id === activeProductId) || null
  }
}
const store = new Vuex.Store({
	state,
  getters,
  mutations
})

const Shop =  {
	created() { this.loadData() },
  watch: {
  	$route() { this.loadData() }
  },
	computed: {
  	product() { return this.$store.getters.activeProduct }
  },
  methods: {
  	loadData() {
    	this.$store.commit('setActiveProduct', {id: null})
    	setTimeout(() => { // simulate async data fetching...
     this.$store.commit('setActiveProduct', {id: this.$route.params.id})
    }, 2000)
    }
  },
	template: '
Shop for: {{product.name}}
' } const routes = [ { path: '/', name: 'root', component: {template: '
Root Path
'}, meta: { bcLinkText: 'Default Page'}, }, { path: '/products', name: 'products', component: { template: '#products'}, meta: { bcLinkText: "Products"}, children: [ { path: ':id', name: 'shop', component: Shop, meta: { breadcrumbs: true, bcGetter: 'activeProduct', bcLinkText: product => product.name, bcLoadingText: 'Loading Productname...' }, } ] } ] const router = new VueRouter({ mode: 'history', base: '/_display/', routes }) Vue.component('breadcrumb', { props: ['route'], template: '#breadcrumb', beforeCreate() { this.$options.computed.value = function() { if (this.route.meta.bcGetter) { return this.$store.getters[this.route.meta.bcGetter] } else { return null } } }, computed: { formattedValue() { return this.route.meta.bcLinkText(this.value) }, loadingText() { const loadingText = this.route.meta.bcLoadingText return loadingText ? loadingText : 'Loading...' } } }) new Vue({ el: '#app', router, store })

Step 2: HTML Part

Dynamic Breadcrumbs

Breadcrumbs:

Open Products Route
$data:
    {{$store.state}}
  

bootstrap vue breadcrumb example
Web Programming Tutorials Example with Demo

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Dynamic breadcrumbs in Vue JS.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment