Explorar el Código

隐藏弹窗多余render优化

zhouna hace 6 años
padre
commit
c3442d0ecd
Se han modificado 1 ficheros con 13 adiciones y 5 borrados
  1. 13 5
      src/store/actions/homePage.js

+ 13 - 5
src/store/actions/homePage.js

@@ -31,17 +31,25 @@ export const showDrop=(state,action)=>{
 export const confirmHide=(state,action)=>{
   let res = Object.assign({},state);
   let obj = res.showDrop||{};
+  //页面空白时不更新
+  if(Object.keys(res.showDrop).length==0){
+    return res;
+  }
   let temp = Object.assign({},obj);
   let keyArr = Object.keys(obj);
+  let flag = false;
   for(let i=0; i<keyArr.length; i++){
-    temp[JSON.parse(keyArr[i])] = false;
+    if(temp[keyArr[i]]){
+      flag = true;
+      temp[keyArr[i]] = false;
+    }
+  }
+  if(!flag){      //未修改值时不更新
+    return res;
   }
-  /*for(let i in obj){
-    temp[i] = false;
-  };*/
   res.showDrop = temp;
   res.commSymHide = true;
-  res.update=Math.random();
+  //res.update=Math.random();     //temp已是新对象,无需再update唤起更新
   return res;
 }