Ver código fonte

对结果进行缓存 不频繁请求接口

ooo 1 ano atrás
pai
commit
63f322102a
1 arquivos alterados com 7 adições e 0 exclusões
  1. 7 0
      src/views/pro-operation/call-materiel/desperse.vue

+ 7 - 0
src/views/pro-operation/call-materiel/desperse.vue

@@ -54,7 +54,13 @@ const changeRightEl = (row: any, index: number) => {
 const testClick = () => {
   console.log("here---in");
 };
+const cacheDataMap = ref(new Map());
 const accessoriesDataList = (index: number) => {
+  //对结果进行缓存 不频繁请求接口
+  if (cacheDataMap.value.has(index)) {
+    merterielBoxes.value = cacheDataMap.value.get(index);
+    return;
+  }
   const firstObj = leftTrees?.value[index];
   //dictLabel: "炼胶",dictSort: 1,dictValue: "1"
   const queryAccessoriesParam = {
@@ -69,6 +75,7 @@ const accessoriesDataList = (index: number) => {
     .then((res) => {
       // console.log("onMounted", res.data);
       merterielBoxes.value = res.data;
+      cacheDataMap.value.set(index, res.data);
     })
     .finally(() => {
       loading.value = false;