Answer the question
In order to leave comments, you need to log in
Why is fetch not working correctly in nuxt?
Nuxt has an updated fetch that allows you to fetch data from the server directly in the component. So, I have a dynamic page. Here she is:
<template>
<div>
<component
:is="res"
/>
</div>
</template>
<script>
import Card from '@/components/main/pages/Card'
import Post from '@/components/main/pages/Post'
import Tag from '@/components/main/pages/Tag'
export default {
components: {
Card,
Post,
Tag
},
async asyncData({store, params}) {
const res = await store.dispatch('data/getData', params.slug)
return {res}
}
}
</script>
data () {
return {
data: ''
}
},
async fetch() {
const res = await this.$axios.$get(`/api/card/${this.$route.params.slug}`)
this.data = res
},
Answer the question
In order to leave comments, you need to log in
On the server side this
is not available, you need to get the same store
from context
as inasyncData
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question