简体   繁体   English

为什么 nuxtServerInit 在站点加载时被多次调用

[英]Why nuxtServerInit is called multiple times on site load

I am working on nuxt-edge + auth.nuxt + vuex project and in the nuxtServerInit method of the store I am only logging a message in the console.我正在研究nuxt-edge + auth.nuxt + vuex项目,在商店的nuxtServerInit方法中,我只在控制台中记录一条消息。 When the site is reloaded the message gets printed multiple times.重新加载站点时,消息会打印多次。 This seems to happen only in dev mode.这似乎只发生在dev模式下。

Any time an asset is requested from your server that results in an error, Nuxt will render and return an individual error for each file.任何时候从您的服务器请求资产导致错误时,Nuxt 都会为每个文件呈现并返回一个单独的错误。 Error pages are treated like any other page in Nuxt.错误页面与 Nuxt 中的任何其他页面一样对待。 This means nuxtSeverInit gets called for your initial request and gets called again for each error request on the server.这意味着 nuxtSeverInit 会针对您的初始请求被调用,并会针对服务器上的每个错误请求再次被调用。

Check your Network requests to track down each error asset that is requested from your Nuxt server.检查您的网络请求以跟踪从您的 Nuxt 服务器请求的每个错误资产。

Just discovered that with nuxt all internal links should be created with NuxtLink, not href's, I had a menu bar with hrefs and saw api requests where I did not expect them, as I used NuxtServerInit in the store, but some other links did not result in extra api calls, these links were NuxtLink's.刚刚发现使用 nuxt 所有内部链接都应该使用 NuxtLink 创建,而不是 href's,我有一个带有 href 的菜单栏,并且看到 api 个请求,这是我没有预料到的,因为我在商店中使用了 NuxtServerInit,但是其他一些链接没有结果在额外的 api 电话中,这些链接是 NuxtLink 的。

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

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