You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修改Nuxt 3中$fetch的30秒超时限制?

Nuxt 3 中延长 $fetch 超时时间的方法

Nuxt 3 的 $fetch 基于 ofetch 实现,默认超时时间为30秒,你可以通过在请求配置中添加 timeout 参数自定义超时时长,单位为毫秒。

修改后的示例代码:

// server/api/render.ts
...
var startTime = performance.now();
try {
    const output = await $fetch(config.MODEL_ENDPOINT_URL + "/render", {
        method: "POST",
        headers: {
            "Content-Type": "application/json",
            Accept: "application/json",
        },
        body: JSON.stringify(input),
        timeout: 60000 // 自定义超时时间,这里设置为60秒,可按需调整
    });
} catch (error) {
    console.log(error)
    var endTime = performance.now();

    console.log(
        "Execution time: " + (endTime - startTime) / 1000
    );
}
...

额外配置(若仍出现超时)

如果设置上述参数后依然超时,可调整 Nuxt 服务器本身的全局超时限制,在 nuxt.config.ts 中修改:

// nuxt.config.ts
export default defineNuxtConfig({
  server: {
    timeout: 60000 // 调整服务器全局请求超时时间
  }
})

内容的提问来源于stack exchange,提问作者Joachim

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 20:22:04