[Vuejs]-Vue.js (vuex). Computed property returns undefined when reloading the page. (Hard coded array of objects data in vuex)

1👍

Thanks for the answer I was able to fix it by adding parseInt in the computed property of ShoeDetail.

  computed: {
    product() {
      return this.$store.getters.getProductById(
        parseInt(this.$route.params.id)
      );
    },
  }

0👍

Do this in the ShoeDetail component:

data: () => {
    data: '',
},
methods: {
    getProduct () {
    this.product = this.$store.getters.getProductById(this.$route.params.id);
    },
},
mounted () {
    this.getProduct();
}

and it should work 🙂

Leave a comment