0

I have a nuxt.js application where fetch () hook is used fetch data from API, as below:

async fetch() {
    await this.$store.dispatch('articles/getArticlesDetails', this.$route.params.id)
}

and I want to use the data returned by API on the client-side and tried to get it in mounted and it is undefined in mounted.

Is there any other efficient way to get and use the data for further making an API call on the client-side .

Bruno Martins
  • 882
  • 2
  • 10
  • 21

1 Answers1

0

I assume your Vuex Action does a Mutation on the State data:

store.js

export const state = () => ({
  dataFromAPI: []
})

Then, you should be able to retrieve the updated State from your _id.vue :

export default {
    computed: {
      apiData() {
        return this.$store.state.dataFromAPI
      }
    }
  }
Bruno Martins
  • 882
  • 2
  • 10
  • 21
zernonia
  • 168
  • 1
  • 4
  • yes that's correct! I can get data in computed property but I want to make an API call further using this data. where should I place that exactly? – Savina Chandla Sep 07 '20 at 14:21
  • you should be able to directly use the data from API to make another API call in your Action – zernonia Sep 07 '20 at 14:35