fix: 修改用户数据加载延迟时间和新鲜度设置
This commit is contained in:
@ -5,8 +5,8 @@ import { defineColadaLoader } from 'unplugin-vue-router/data-loaders/pinia-colad
|
|||||||
async function getUserById(userId: string, { signal }: { signal?: AbortSignal }) {
|
async function getUserById(userId: string, { signal }: { signal?: AbortSignal }) {
|
||||||
console.warn('[getUserById] 被调用, userId :>> ', userId);
|
console.warn('[getUserById] 被调用, userId :>> ', userId);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
console.log('5s 已过', 'userId :>> ', userId);
|
console.log('10s 已过', 'userId :>> ', userId);
|
||||||
}, 5000);
|
}, 1000 * 10);
|
||||||
const res = await fetch(`https://jsonplaceholder.typicode.com/users/${userId}`, { signal });
|
const res = await fetch(`https://jsonplaceholder.typicode.com/users/${userId}`, { signal });
|
||||||
await new Promise((resolve) => setTimeout(resolve, 300));
|
await new Promise((resolve) => setTimeout(resolve, 300));
|
||||||
return await res.json();
|
return await res.json();
|
||||||
@ -20,7 +20,7 @@ export const useUserData = defineColadaLoader('DataLoadersIdSub1UserId', {
|
|||||||
key: (to) => ['users', to.params.userId],
|
key: (to) => ['users', to.params.userId],
|
||||||
// Keep the data "fresh" 10 seconds to avoid fetching the same data too often
|
// Keep the data "fresh" 10 seconds to avoid fetching the same data too often
|
||||||
// 保持数据“新鲜”10秒,以避免过于频繁地获取相同的数据
|
// 保持数据“新鲜”10秒,以避免过于频繁地获取相同的数据
|
||||||
staleTime: 5000,
|
staleTime: 1000 * 10,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const usePageData = defineBasicLoader('DataLoadersIdSub1UserId', async (route) => {
|
export const usePageData = defineBasicLoader('DataLoadersIdSub1UserId', async (route) => {
|
||||||
|
Reference in New Issue
Block a user