简体   繁体   English

为什么nuxt.js会调用SSR中的beforeCreate,created hook?

[英]why does nuxt.js call the beforeCreate, created hook in SSR?

Currently, we are developing SPA using nuxt.js. One question arises is that the beforeCreate and created hooks are called in SSR mode, and when the SSR is finished, they are called again in CSR.目前我们正在使用nuxt.js开发SPA,有一个问题是在SSR模式下调用了beforeCreate和created hooks,当SSR结束后,在CSR中再次调用。

Just looking at the nuxt.js life cycle image, I am confused because there is no explanation for the content.只看 nuxt.js 生命周期图像,我很困惑,因为没有对内容进行解释。

Any answers would be appreciated!任何答案将不胜感激!

Nuxt use the Vue SSR under the hood and you can find a start of explanation in it documentation: https://ssr.vuejs.org/guide/universal.html#component-lifecycle-hooks Nuxt 在引擎盖下使用 Vue SSR,您可以在它的文档中找到解释的开始: https://ssr.vuejs.org/guide/universal.html#component-lifecycle-hooks

Component Lifecycle Hooks组件生命周期挂钩

Since there are no dynamic updates, of all the lifecycle hooks, only beforeCreate and created will be called during SSR .由于没有动态更新,在所有生命周期钩子中,只有 beforeCreate 和 created 会在 SSR 期间被调用 This means any code inside other lifecycle hooks such as beforeMount or mounted will only be executed on the client.这意味着其他生命周期挂钩(例如 beforeMount 或 mounted)中的任何代码都只会在客户端上执行。

First, the Vue SSR server runs the lifecycle hooks to build the HTML content from the Vue app.首先,Vue SSR 服务器运行生命周期挂钩以从 Vue 应用构建 HTML 内容。 Then after the Vue Hydratation on client side, the front-end have to re-play all the Vue livecycle hooks in order to run the JS app in your browser.然后在客户端的 Vue Hydratation 之后,前端必须重新播放所有 Vue livecycle hooks 才能在浏览器中运行 JS 应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM