How does nuxt get data before vuex instantiation?

I need to get the data before vuex instantiation, and I need to request the background.
then copy the data to vuex.state in vuex
so that the page can get it directly after vuex instantiation.
how does nuxt get data before vuex instantiation?

Jun.27,2022

there are clear documents on nuxt's official website

The
asyncData method is called before each load of the component (limited to the page component). It can be called before the server or routing update. When this method is called, the first parameter is set to the context object of the current page, you can use the asyncData method to get the data, and Nuxt.js will return the data returned by the data fusion component data method returned by asyncData to the current component.

Note: because the asyncData method is called before the component is initialized, there is no way to reference the component's instance object through this within the method.

Nuxt.js provides several different ways to use the asyncData method. You can choose the one you are familiar with:

returns a Promise, and nuxt.js waits for the Promise to be parsed before setting the component's data to render the component.
use async or await
to specify a callback function for the second parameter. Note: the callback function must conform to the general NodeJs callback function: callback (err, data)

ide/async-data-sharpasyncdata-%E6%96%B9%E6%B3%95" rel=" nofollow noreferrer "> Asynchronous data


have you solved the problem? I don't know how to deal with global asynchronous data

.
Menu