Building an E-Commerce Store - Browsing Products Chapter 10
template: `<div>
<div v-if="category"></div>
<page-not-found v-if="categoryNotFound"></page-not-found>
</div>`,
components: {
PageNotFound
},
props: {
slug: String
},
data() {
return {
categoryNotFound: false,
}
},
computed: {
category() {
}
}
};
Inside the category computed function, load the correct category from the store based on
the slug. If it is not on the list, mark the categoryNotFound variable to true - similar to
what we did in the ProductPage component:
computed: {
category() {
let category;
if(Object.keys(this.$store.state.categories).length) {
category = this.$store.state.categories[this.slug];
if(!category) {
this.categoryNotFound = true;
}
}
return category;
}
}