diff --git a/README.md b/README.md index d8dd9aa..59aa593 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [中文版](https://github.com/chenfengjw163/vue-json-viewer/blob/master/README_CN.md) -Simple JSON viewer component, for Vue.js 2. +Simple JSON viewer component, for Vue.js 2 or 3. Support for incremental update components @@ -20,12 +20,18 @@ Support for incremental update components ## Installing Using npm: ``` -$ npm install vue-json-viewer --save +$ npm install vue-json-viewer@2 --save +// Vue2 +$ npm install vue-json-viewer@3 --save +// Vue3 ``` Using yarn: ``` -$ yarn add vue-json-viewer +$ yarn add vue-json-viewer@2 +// Vue2 +$ yarn add vue-json-viewer@3 +// Vue3 ``` ## Example diff --git a/README_CN.md b/README_CN.md index 99e2c15..48811bf 100644 --- a/README_CN.md +++ b/README_CN.md @@ -1,6 +1,6 @@ # vue-json-viewer -简单易用的json内容展示组件,支持vue@2.0+,支持SSR,组件支持增量渲染即使大文件json也可以快速渲染。 +简单易用的json内容展示组件,支持vue@2和3,支持SSR,组件支持增量渲染即使大文件json也可以快速渲染。 [![Travis](https://img.shields.io/travis/chenfengjw163/vue-json-viewer/master.svg?style=flat-square)](https://travis-ci.org/chenfengjw163/vue-json-viewer) [![npm](https://img.shields.io/npm/v/vue-json-viewer.svg?style=flat-square)](https://www.npmjs.com/package/vue-json-viewer) @@ -14,12 +14,18 @@ ## 安装 使用 npm: ``` -$ npm install vue-json-viewer --save +$ npm install vue-json-viewer@2 --save +// Vue2 +$ npm install vue-json-viewer@3 --save +// Vue3 ``` 使用 yarn: ``` -$ yarn add vue-json-viewer +$ yarn add vue-json-viewer@2 +// Vue2 +$ yarn add vue-json-viewer@3 +// Vue3 ``` ## 示例 diff --git a/example/package.json b/example/package.json new file mode 100644 index 0000000..3e70ae6 --- /dev/null +++ b/example/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "vue-json-viewer": "^3.0.1" + } +} diff --git a/lib/json-box.vue b/lib/json-box.vue index f67ea37..d509098 100644 --- a/lib/json-box.vue +++ b/lib/json-box.vue @@ -27,19 +27,31 @@ export default { default: 0 }, previewMode: Boolean, + forceExpand: Boolean, + showArrayIndex: Boolean, }, data() { return { - expand: true + expand: true, + forceExpandMe: this.forceExpand, } }, mounted() { - this.expand = this.previewMode || (this.depth >= this.expandDepth ? false : true) + this.expand = this.previewMode || (this.depth >= this.expandDepth ? false : true) || this.forceExpandMe }, methods: { toggle() { this.expand = !this.expand + this.dispatchEvent() + }, + toggleAll() { + this.expand = !this.expand + this.forceExpandMe = this.expand + + this.dispatchEvent() + }, + dispatchEvent() { try { this.$el.dispatchEvent(new Event('resized')) } catch (e) { @@ -65,7 +77,7 @@ export default { let elements = [] let dataType - if (this.value === null || this.value === undefined) { + if (this.value === null || this.value === undefined) { dataType = JsonUndefined } else if (Array.isArray(this.value)) { dataType = JsonArray @@ -90,7 +102,13 @@ export default { 'jv-toggle': true, open: !!this.expand }, - onClick: this.toggle + onClick: (event) => { + if (event.altKey) { + this.toggleAll() + } else { + this.toggle() + } + } })) } @@ -113,8 +131,14 @@ export default { depth: this.depth, expand: this.expand, previewMode: this.previewMode, + forceExpand: this.forceExpandMe, + showArrayIndex: this.showArrayIndex, 'onUpdate:expand': value => { this.expand = value + }, + 'onUpdate:expandAll': value => { + this.expand = value + this.forceExpandMe = this.expand } })) diff --git a/lib/json-viewer.vue b/lib/json-viewer.vue index d9340b0..45de14d 100644 --- a/lib/json-viewer.vue +++ b/lib/json-viewer.vue @@ -1,6 +1,9 @@