当 Nuxt 的 SSR 遇到错误时,你如何处理错误?
目前我正在使用error()处理程序,但它在生产中不起作用?这是我的 Nuxt 应用程序的示例。
异步数据
async asyncData({ store, route, error }) {
return store.dispatch( NAMESPACES.USERS + ACTIONS.GET_DETAIL, userId ).then(response => ({
data: response,
})).catch((e) => {
error(e)
})
}
Run Code Online (Sandbox Code Playgroud)
错误.vue
<vis-container>
<vis-row class="error">
<vis-col md="8" class="error__component">
<component :is="errorPage" :error="error.statusCode" />
</vis-col>
<vis-col md="8" class="error__contact">
<p class="error__contact__title">{{ $t('error_page.question') }}</p>
</vis-col>
</vis-row>
</vis-container>
</template>
<script>
export default {
props: ['error'],
components: {
NotFound: () => import('@/components/error/NotFound'),
InternalServerError: () => import('@/components/error/InternalServerError'),
},
computed: {
errorPage() {
if …Run Code Online (Sandbox Code Playgroud) 我的代码:
export const useMenuStore = defineStore("menuStore", {
state: () => ({
menus: [],
}),
actions: {
async nuxtServerInit() {
const { body } = await fetch("https://jsonplaceholder.typicode.com/posts/1").then((response) => response.json());
console.log(body);
this.menus = body;
resolve();
},
},
});
Run Code Online (Sandbox Code Playgroud)
NuxtServerInit 无法在 nuxt js vuex 模块模式下进行初始页面渲染。任何人都知道此错误,请帮助我。