Building an E-Commerce Store - Browsing Products Chapter 10
'kenda-tube',
'colorful-fixie-lima',
'oury-grip-set',
'pure-fix-pedals-with-cages'
]
}
}
}
The last thing we need to do is check whether the slug exists. If not, assign our new object
to the category variable within the computed function:
category() {
let category;
if(Object.keys(this.$store.state.categories).length) {
if(this.slug) {
category = this.$store.state.categories[this.slug];
} else {
category = this.categoryHome;
}
if(!category) {
this.categoryNotFound = true;
}
}
return category;
}
Head to the home page and verify your new component is working. If it is, you can delete
HomePage.js and remove it from index.html. Update the category route to also include
the category list in the sidebar and use the props object:
{
path: '/category/:slug',
name: 'Category',
components: {
default: CategoryPage,
sidebar: ListCategories
},
props: {
default: true,
sidebar: true
}
},