亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

如何在自訂掛鉤內(nèi)建立 useFetch 的副本?
P粉928591383
P粉928591383 2023-08-28 15:24:54
0
1
510
<p>我正在嘗試創(chuàng)建一個(gè)可多次使用的鉤子,但我得到的行為不是我期望的</p> <p>/composables/fetch.ts</p> <pre class="brush:js;toolbar:false;">export const useFetchWithErrorHandler = async (url: string, options?: FetchOptions) => { const route = useRoute(); const { API_BASE_URL, API_PREFIX } = useRuntimeConfig(); console.log(url, options); return new Promise(async (resolve, reject) => { const response = await useFetch(API_PREFIX url, { ...options, baseURL: API_BASE_URL, initialCache: false, async onResponse({ request, response, options }) { console.log('[fetch response]', response); }, async onResponseError({ request, response, options }) { console.log('[fetch response error]'); }, }); resolve(response); }); </pre> <p>只觸發(fā)第一個(gè)請求</p> <pre class="brush:js;toolbar:false;">const { data: response } = await useFetchWithErrorHandler(`page-1`, { pick: ['data'], }); const { data: response } = await useFetchWithErrorHandler(`page-2`, { pick: ['data'], }); </pre></p>
P粉928591383
P粉928591383

全部回覆(1)
P粉032900484

useFetch 使用快取來避免多個(gè)相同的請求。

如果您在選項(xiàng)中設(shè)定initialCache: false,則可以停用緩存,例如

useFetch(API_PREFIX + url, {
    ...options,
    initialCache: false,
  }
)
最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板