diff --git a/History.md b/History.md
index 60983ec..55fa98d 100644
--- a/History.md
+++ b/History.md
@@ -1,3 +1,7 @@
+## 2.2.14 2020-10-13
+
+- Add Preview Mode
+
## 2.2.14 2020-07-27
- Allow add specific style for float and integer numbers [pr](https://github.com/chenfengjw163/vue-json-viewer/pull/51)
diff --git a/README.md b/README.md
index 13e1c24..d8dd9aa 100644
--- a/README.md
+++ b/README.md
@@ -153,6 +153,7 @@ import 'vue-json-viewer/style.css'
| `theme` | Add a custom CSS class for theming purposes | `jv-light` |
| `expanded` | Default expand the view | `false` |
| `timeformat` | custom time format function | time => time.toLocaleString() |
+| `preview-mode` | no expand mode | `false` |
## Listeners
diff --git a/README_CN.md b/README_CN.md
index aa02650..99e2c15 100644
--- a/README_CN.md
+++ b/README_CN.md
@@ -147,6 +147,7 @@ import 'vue-json-viewer/style.css'
| `theme` | 添加一个自定义的样式class用作主题 | `jv-light` |
| `expanded` | 默认展开视图 | `false` |
| `timeformat` | 自定义时间格式函数 | time => time.toLocaleString() |
+| `preview-mode` | 不可折叠模式,默认全部展开 | `false` |
## 主题
diff --git a/example/app.js b/example/app.js
index b6fd71d..40ea7d2 100644
--- a/example/app.js
+++ b/example/app.js
@@ -18,6 +18,17 @@ new Vue({
}
return (
+
= this.expandDepth ? false : true
+ this.expand = this.previewMode || (this.depth >= this.expandDepth ? false : true)
},
methods: {
toggle() {
@@ -71,7 +72,7 @@ export default {
}
const toggle = this.keyName && (this.value && (Array.isArray(this.value) || (typeof this.value === 'object' && Object.prototype.toString.call(this.value) !== '[object Date]')))
- if (toggle) {
+ if (!this.previewMode && toggle) {
elements.push(h('span', {
class: {
'jv-toggle': true,
@@ -103,7 +104,8 @@ export default {
keyName: this.keyName,
sort: this.sort,
depth: this.depth,
- expand: this.expand
+ expand: this.expand,
+ previewMode: this.previewMode,
},
on: {
'update:expand': value => {
@@ -115,7 +117,7 @@ export default {
return h('div', {
class: {
'jv-node': true,
- 'toggle': toggle
+ 'toggle': !this.previewMode && toggle
}
}, elements)
}
diff --git a/lib/json-viewer.vue b/lib/json-viewer.vue
index 77fa24a..aa4181f 100644
--- a/lib/json-viewer.vue
+++ b/lib/json-viewer.vue
@@ -25,6 +25,7 @@
ref="jsonBox"
:value="value"
:sort="sort"
+ :preview-mode="previewMode"
/>
value.toLocaleString(),
+ },
+ previewMode: {
+ type: Boolean,
+ default: false,
}
},
provide () {
diff --git a/lib/types/json-array.vue b/lib/types/json-array.vue
index 633fa67..41758a0 100644
--- a/lib/types/json-array.vue
+++ b/lib/types/json-array.vue
@@ -17,7 +17,8 @@ export default {
default: 0
},
sort: Boolean,
- expand: Boolean
+ expand: Boolean,
+ previewMode: Boolean,
},
data() {
return {
@@ -61,7 +62,7 @@ export default {
render (h) {
let elements = []
- if (!this.keyName) {
+ if (!this.previewMode && !this.keyName) {
elements.push(h('span', {
class: {
'jv-toggle': true,
@@ -94,6 +95,7 @@ export default {
// keyName: key,
depth: this.depth + 1,
value,
+ previewMode: this.previewMode,
}
}))
})
diff --git a/lib/types/json-object.vue b/lib/types/json-object.vue
index 2f4da75..24415f9 100644
--- a/lib/types/json-object.vue
+++ b/lib/types/json-object.vue
@@ -17,7 +17,8 @@ export default {
default: 0
},
expand: Boolean,
- sort: Boolean
+ sort: Boolean,
+ previewMode: Boolean,
},
data() {
return {
@@ -69,7 +70,7 @@ export default {
render (h) {
let elements = []
- if (!this.keyName) {
+ if (!this.previewMode && !this.keyName) {
elements.push(h('span', {
class: {
'jv-toggle': true,
@@ -106,6 +107,7 @@ export default {
keyName: key,
depth: this.depth + 1,
value,
+ previewMode: this.previewMode,
}
}))
}
diff --git a/package.json b/package.json
index ea6877e..6807d4d 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "vue-json-viewer",
- "version": "2.2.14",
+ "version": "2.2.15",
"description": "vuejs展示json的组件",
"main": "vue-json-viewer.js",
"files": [