我的代码:
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 模块模式下进行初始页面渲染。任何人都知道此错误,请帮助我。
我的后端(API 端点)正在 https://localhost:44308/api 上运行。在这种情况下,Nuxt3.js 会给出以下错误:
request to https://localhost:44308/api/menus failed, reason: self signed certificate ()
at async $fetchRaw2 (/C:/D/MyApp/Source/WebUser/app/node_modules/ohmyfetch/dist/chunks/fetch.mjs:131:20)
at async Proxy.fetchData (/C:/D/MyApp/Source/WebUser/app/.nuxt/dist/server/server.mjs:52133:22)
at async setup (/C:/D/MyApp/Source/WebUser/app/.nuxt/dist/server/server.mjs:68832:5)
Run Code Online (Sandbox Code Playgroud)
我的代码:
async fetchData() {
const config = useRuntimeConfig();
const result = await $fetch(`${config.apiBase}/menus`, {
headers: {
"Content-Type": "application/json",
"Accept-Language": "en",
// Authorization: `Bearer ${useRuntimeConfig().apiSecret}`,
},
});
console.log(result);
return result;
}
Run Code Online (Sandbox Code Playgroud)
解决这个问题的办法是什么?我看到建议运行 Nuxt3.js 的线程。请有人帮助我。非常感谢