Questions tagged [asyncdata]

Nuxt.js' asyncData is a way of blocking a specific page render, for data fetching and then proceed by returning the computed data.

Looking like this

async asyncData({ params, $http }) {
  const post = await $http.$get(`https://api.nuxtjs.dev/posts/${params.id}`)
  return { post }
}

It is an alternative to the fetch() hook. More details on the differences between the two can be found here: https://nuxtjs.org/blog/understanding-how-fetch-works-in-nuxt-2-12/

38 questions
8
votes
0 answers

Nuxt.js: How to debug server side after nuxt build (logging some information)

I am using nuxt.js for my frontend app. I currently have a problem with asyncData especially the first time it is run (which is on the server). When building my app ($ nuxt build and serving it via $ serve), I currently have no real possibility to…
Merc
  • 4,241
  • 8
  • 52
  • 81
6
votes
2 answers

Fetch query string value from URL with NuxtJS and AsyncData method

I try to fetch value of the name parameter in URL: http://fakelocalhost:3000/page?name=test I'm using NuxtJS (v2.11.0) and TypeScript, with nuxt-property-decorator package (v2.5.0). But, I get an undefined result with console.log(params.name). Here,…
pirmax
  • 2,054
  • 8
  • 36
  • 69
5
votes
1 answer

nuxt watchQuery not working on update route with new query

when i add a new query using $router.push to route Nuxt watchQuery not working and asyncData not fetching api and remount children components. please attention to "New query" and not exist any query by default.(after created new query and then…
5
votes
0 answers

nuxtjs: How to deal with asyncdata inside layout template

I'm using nuxtjs to render my page on the server. To load data inside my page with asyncdata is no problem, but how can I load my data inside my default layout which includes header and footer? Because asyncdata is not available there. Should I use…
Gregor Voinov
  • 2,203
  • 7
  • 34
  • 52
4
votes
2 answers

NuxtJS - Use asyncData method in layout or component

How I can use asyncData in layout or component (forbidden apparently) ? Because my sidebar component is used in default layout, and I need to use asyncData to display data from backend. And if I use Vuex to fetch data... I don't know how I can fetch…
pirmax
  • 2,054
  • 8
  • 36
  • 69
4
votes
5 answers

Call mixin function from asyncData() method of the page component with Nuxt.js

Can I call mixin function from asyncData() method of the page component with Nuxt.js? My code: