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

Nuxt3中useFetch执行后navigateTo无法跳转的问题求助

Nuxt3中useFetch执行后navigateTo无法跳转的问题求助

各位好,我最近在Nuxt3项目里碰到了个棘手的小问题——在useFetch的onResponse钩子里面调用navigateTo做外部跳转,结果完全没反应,有没有大佬能帮忙分析下原因呀?

我把代码简化后是这样的:

<template>
  <div></div>
</template>

<script setup lang="ts">
const { slug } = useRoute().params

await useFetch(`http://localhost/${slug}`, {
  async onResponse({ response: { _data: data } }) {
    // 我特意用谷歌地址测试外部跳转,实际后续会换成API返回的地址
    const url = new URL('https://google.com')
    await navigateTo(url.href, {
      external: true
    })
  }
})
</script>

我本来以为请求完成后会自动跳转到指定的外部链接,结果页面纹丝不动,控制台也没报错,实在摸不着头脑,求各位给点思路!

备注:内容来源于stack exchange,提问作者Caio Kawasaki

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.20 07:13:14