Browse Source

feat: Need to handle deep objects otherwise it will return :[object Object]

赵思 2 years ago
parent
commit
df5e1eea14
1 changed files with 9 additions and 0 deletions
  1. 9 0
      src/utils/dataExporter.js

+ 9 - 0
src/utils/dataExporter.js

@@ -54,6 +54,15 @@ export default function (
     const extractObj = (obj) => {
       if (typeof obj !== 'object') return [obj];
 
+      // 需要处理深层对象 不然会返回:[object Object]
+      const kes = Object.keys(obj);
+      kes.forEach((key) => {
+        const itemValue = obj[key];
+        if (typeof itemValue === 'object') {
+          obj[key] = JSON.stringify(itemValue);
+        }
+      });
+
       return Object.values(obj);
     };