Nuxt.js: server-side fetching data problem

Created on 27 Jun 2017  路  4Comments  路  Source: nuxt/nuxt.js

I want to fetch data from the server side, my code is like this:

image

The problem is when I visit the page first time, there is no data injected(I check the webpage source code), and I try the second time which is good, then I can always get data normally.
here is the CLI log:

image

I notice that the blue number first time is too large than the second time visiting(maybe cause by cache), my question is why nuxt doesn鈥榯 wait until fetching data completely? how can I fix that problem?

This question is available on Nuxt.js community (#c847)

Most helpful comment

@ummo not sure how your dispatch function looks like, maybe you forgot to return a promise?

All 4 comments

@ummo not sure how your dispatch function looks like, maybe you forgot to return a promise?

Hi,
You should use async/await like this:

async fetch() {
  await store.dispatch('templateList', ...)
  return store.dispatch('categoryList', ...)
}

@dohomi solved my problem, thanks

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

o-alexandrov picture o-alexandrov  路  3Comments

surmon-china picture surmon-china  路  3Comments

vadimsg picture vadimsg  路  3Comments

pehbehbeh picture pehbehbeh  路  3Comments

msudgh picture msudgh  路  3Comments