When you set a data item to a getter in Product.vue, it gets assigned only once. If the getter changes, the data doesn't change with it:
data() {
return {
products: this.$store.getters.filterProducts // ? Incorrect
}
}
Use a computed instead with mapGetters
to keep the component data synced with the Vuex data:
import { mapGetters } from 'vuex';
computed: {
...mapGetters(['filterProducts']) // ? Correct
}
Change your template to use that computed:
<div v-for="product in filterProducts" :key="product.id">
<h4 class="card-title product__title">
{{ product.title }}
</h4>
</div>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…