fix: 修改用户数据加载延迟时间和新鲜度设置
All checks were successful
/ playwright (push) Successful in 1m58s
/ build-and-deploy-to-vercel (push) Successful in 1m32s
/ depcheck (push) Successful in 1m26s

This commit is contained in:
严浩
2024-12-20 15:33:55 +08:00
parent 50e0c5ebc6
commit 49fc15b1b6

View File

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