// 获取 InProcessCount 数据 async function getInProcessCount(routeritem: RouteRecordRaw) { const len = await store.dispatch('ESourcingModule/GetMyRequest', searchView.value).then((list) => { // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call return list.filter((o: { ViewType: string }) => o.ViewType === 'InClarification' || o.ViewType === 'SupplementEventDetails').length }) if (routeritem?.meta) { // eslint-disable-next-line @typescript-eslint/restrict-template-expressions routeritem.meta.title = `${routeritem.meta?.title}(${len})`; } return len as number }
时间: 2024-02-20 10:59:34 浏览: 158
可以将 `getInProcessCount` 方法的结果缓存下来,以后再调用时直接使用缓存的结果,避免重复执行。例如:
```
let inProcessCount: number | undefined;
async function getInProcessCount(routeritem: RouteRecordRaw) {
if (inProcessCount !== undefined) {
return inProcessCount;
}
const len = await store.dispatch('ESourcingModule/GetMyRequest', searchView.value).then((list) => {
return list.filter((o: { ViewType: string }) => o.ViewType === 'InClarification' || o.ViewType === 'SupplementEventDetails').length;
});
if (routeritem?.meta) {
routeritem.meta.title = `${routeritem.meta?.title}(${len})`;
}
inProcessCount = len;
return len;
}
```
这样,第一次调用 `getInProcessCount` 方法时会执行实际的操作并将结果缓存下来,以后再调用时直接返回缓存的结果,避免重复执行。注意要将 `inProcessCount` 定义在作用域范围之外,以便在多次调用时保留状态。
阅读全文