【问题标题】:Nuxt 3 HTTP request on demand after rendering: a client-side fetch渲染后按需请求 Nuxt 3 HTTP 请求:客户端获取
【发布时间】:2021-12-24 13:28:42
【问题描述】:

Nuxt 3 具有那些惊人的数据获取功能(例如:useFetch),但我发现我需要在渲染时间之后发出请求(例如:从按钮调用并发送搜索词)。

据我所知,useFetch 不能在客户端工作,这是我正在尝试做的事情

<template>

<button @click="goSearch()">Search</button>

</template>

setup() {
        const goSearch = async () => {
            const { data } = await useFetch('search', () => $fetch('/api/search'));
            console.log(data.value);
        };

        return { goSearch };
    },
}


nuxt3 是否提供了内置函数来按需发出http请求(客户端官方http axios之类的)?

【问题讨论】:

    标签: fetch nuxt.js nuxt3


    【解决方案1】:

    $fetch 应该可以工作。问题是一个小错误,现在已修复。如果您遇到此错误,只需升级 nuxt/ohmyfetch 库

    npx nuxi upgrade --force

    更多: https://github.com/nuxt/framework/issues/2502#issuecomment-999783226

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-16
      • 1970-01-01
      • 2013-03-15
      • 1970-01-01
      • 2020-02-25
      • 2019-07-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多