From 8953e9d1da5241aaf4624f5c3f9a0893beeb04cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=B3=B0?= Date: Wed, 4 Sep 2019 16:16:31 +0800 Subject: [PATCH] feat: Optimize memory --- lib/types/json-array.vue | 30 ++++++++++++++++-------------- lib/types/json-object.vue | 32 +++++++++++++++++--------------- package.json | 2 +- 3 files changed, 34 insertions(+), 30 deletions(-) diff --git a/lib/types/json-array.vue b/lib/types/json-array.vue index e1f126d..96b06e7 100644 --- a/lib/types/json-array.vue +++ b/lib/types/json-array.vue @@ -94,20 +94,22 @@ export default { innerText: '[' } })) - this.ordered.forEach((value, key) => { - elements.push(h(JsonBox, { - key, - style: { - display: this.expand ? undefined : 'none' - }, - props: { - sort: this.sort, - // keyName: key, - depth: this.depth + 1, - value, - } - })) - }) + if (this.expand) { + this.ordered.forEach((value, key) => { + elements.push(h(JsonBox, { + key, + style: { + display: this.expand ? undefined : 'none' + }, + props: { + sort: this.sort, + // keyName: key, + depth: this.depth + 1, + value, + } + })) + }) + } if (!this.expand && this.value.length) { elements.push(h('span', { diff --git a/lib/types/json-object.vue b/lib/types/json-object.vue index 9296f16..981f179 100644 --- a/lib/types/json-object.vue +++ b/lib/types/json-object.vue @@ -91,22 +91,24 @@ export default { } })) - for (let key in this.ordered) { - if (this.ordered.hasOwnProperty(key)) { - let value = this.ordered[key] + if (this.expand) { + for (let key in this.ordered) { + if (this.ordered.hasOwnProperty(key)) { + let value = this.ordered[key] - elements.push(h(JsonBox, { - key, - style: { - display: !this.expand ? 'none' : undefined - }, - props: { - sort: this.sort, - keyName: key, - depth: this.depth + 1, - value, - } - })) + elements.push(h(JsonBox, { + key, + style: { + display: !this.expand ? 'none' : undefined + }, + props: { + sort: this.sort, + keyName: key, + depth: this.depth + 1, + value, + } + })) + } } } diff --git a/package.json b/package.json index ee2ba21..c675cf4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vue-json-viewer", - "version": "2.2.3", + "version": "2.2.4", "description": "vuejs展示json的组件", "main": "vue-json-viewer.js", "files": [