I want to transform this method. I have this vue.js code:
computed: {
...mapGetters('user/auth', ['Id']),
},
async mounted() {
await this.doFetchCustomer(this.Id)
},
methods: {
async doFetchCustomer(Id) {
const app = { $axios: this.$axios }
const datas = (await customerApi.getData(app, Id)) || []
console.log(datas)
},
},
I want to transform this code to nuxt asyncData but what I have tried below isn't working. How can I transform it properly?
computed: {
...mapGetters('user/auth', ['Id'])
},
async asyncData({$axios}) {
const datas = (await customerApi.getData($axios, this.Id )) || [];
console.log(datas);
return {datas}
}
mounted()or in thefetch()hook?mapGettersis takingId, while yourgetDatafunction is usingthis.id? Sure this is not an issue here? Do you seedatasin yourconsole.log?asyncDataby editing your question and the one that is triggering the navigation.