Complete Vue.js 2 Web Development_ Practical guide to building end-to-end web development solutions with Vue.js 2

(singke) #1
Building an E-Commerce Store - Browsing Products Chapter 10

category.values[item.handle] = {
...item,
count: [handle]
}
}
}
}

Viewing the app in the browser should reveal your dynamically-added filters, along with
the original ones we had added.


Resetting filters


When navigating between categories you will notice that, currently, the filters do not reset.


This is because we are not clearing the filters between each navigation, and the arrays are
persisting. This is not ideal, as it means they get longer as you navigate around and do not


apply to the products listed.


To remedy this, we can create a method that returns our default topic object and, when the
slug updates, call the method to reset the topics object. Move the topics object to a new


method titled defaultTopics:


methods: {
defaultTopics() {
return {
vendor: {
title: 'Manufacturer',
handle: 'vendor',
checked: [],
values: {}
},
tags: {
title: 'Tags',
handle: 'tags',
checked: [],
values: {}
}
}
},

addTopic(category, item) {
...
}

updateFilters() {
Free download pdf