https://zh.nuxtjs.org/docs/2.x/concepts/nuxt-lifecycle
https://ssr.vuejs.org/guide/universal.html#component-lifecycle-hooks
生命周期
由于没有动态更新所有的生命周期挂钩的,只有beforeCreate和created将SSR中被调用。这意味着其他生命周期钩子中的任何代码,例如beforeMount或mounted只会在客户端上执行。
server
对于 SSR,将对您的应用程序的每个初始请求执行这些步骤
- The server starts (nuxt start)
- The generation process starts (nuxt generate)
- Nuxt hooks
- serverMiddleware
- Server-side Nuxt plugins
- in order as defined in nuxt.config.js
- nuxtServerInit
- 只能定义在 store/index.js
- Middleware
- Global middleware
- Layout middleware
- Route middleware
- asyncData
- beforeCreate
- created
- The new fetch (top to bottom, siblings = parallel)
- Serialization of state (render:routeContext Nuxt.js hook)
- the HTML rendering happens (render:route Nuxt.js hook)
- render:routeDone hook when HTML has been sent to the browser
- generate:before Nuxt.js hook
- HTML files are generated
- Full static generation
- e.g. static payloads are extracted
- generate:page (HTML editable)
- generate:routeCreated (Route generated)
- Full static generation
- generate:done when all HTML files have been generated
client
- Receives the HTML
- Loading assets (e.g. JavaScript)
- Vue Hydration
- Middleware
- Global middleware
- Layout middleware
- Route middleware
- client-side Nuxt.js plugin
- in order as defined in nuxt.config.js
- asyncData (blocking)
- beforeCreate (Vue lifecycle method)
- created (Vue lifecycle method)
- The new fetch (top to bottom, siblings = parallel) (non-blocking)
- beforeMount (Vue lifecycle method)
- mounted (Vue lifecycle method)