我有nuxt.js
一个用户可以登录的应用程序。每当使用nuxt/auth
模块对用户进行身份验证时。我希望应用程序使用nuxtServerInit
.
目前我在我的nuxtServerInit
:
export const actions = {
async nuxtServerInit({ dispatch }) {
if (this.$auth.loggedIn) {
await dispatch('products/getProducts')
...
}
}
}
如果我已通过身份验证并且页面已刷新,则此方法效果很好。问题似乎是每当我在身份验证后被重定向时,这些操作都不会被调用,因此不会填充store
.
我尝试改用该fetch
方法,但仅适用于带有该fetch
语句的页面,而不是我的应用程序中的每个页面。此外,我不希望每次页面更改都进行 http 调用。