S
S
Seva2018-10-17 16:32:23
Vue.js
Seva, 2018-10-17 16:32:23

Why isn't the computed property updated?

computed: {
    ...mapGetters(['products', 'categories']),
    category () {
      return this.categories.find(category => category.id === this.$route.params.category)
    }
  },

When the component is mounted, the categories array is empty. An action is dispatched from another component on its mounted, and the categories is populated. However, category remains undefined as it was.
How is it customary to act in such cases? Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-10-17
@Zewkin

category.id === this.$route.params.category

I would guess the problem is here. Does an object exist with the id specified in $route.params.category? And doesn't it sound like you're trying to compare values ​​of different types? - let's say category.id is a number and params.category is a string.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question