[Vuejs]-How to get more info knowing only ID

0👍

The solution i would recommend is using Vuex to manage your data. Vuex will give you the ability to create getters that you can import into the components that require data. With that data you can filter the data down to only the item you are looking for.

Ive created a repo on my Git that you can have a look at to get a better idea of what i mean.
Visit https://github.com/FloydWatson/furnitureapp

Ive utilized Vuex for state management and vue-router to create the routing paths that have an id in them.

Within the page furniture.vue I get the list of furniture and find the item im looking for using route parameters

 computed: {
    ...mapGetters(["allFurniture"]),
    // get the details here
    loadedItem() {
      return this.allFurniture.find((item) => item.id == this.$route.params.id);
    },
  },

This is done in a computed field so that if the data was updated our Vuex would let the page know and our data would dynamically update.

Ive tried to leave some comments in there so you can see whats going on easier. Feel free to ask me if theres any other clarification you need.

Happy coding

Leave a comment