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