diff --git a/History.md b/History.md new file mode 100644 index 0000000..f2d408e --- /dev/null +++ b/History.md @@ -0,0 +1,3 @@ +## 2.2.13 2020-07-14 + +- Add timeformat props to support custom time format [pr](https://github.com/chenfengjw163/vue-json-viewer/pull/48) \ No newline at end of file diff --git a/README.md b/README.md index 87b5cda..b6c02c5 100644 --- a/README.md +++ b/README.md @@ -152,6 +152,7 @@ import 'vue-json-viewer/style.css' | `boxed` | Add a fancy "boxed" style to component | `false` | | `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() | ## Listeners diff --git a/README_CN.md b/README_CN.md index 6fbc4df..803b309 100644 --- a/README_CN.md +++ b/README_CN.md @@ -145,6 +145,8 @@ import 'vue-json-viewer/style.css' | `sort` | 按照key排序展示 | `false` | | `boxed` | 为组件添加一个盒样式 | `false` | | `theme` | 添加一个自定义的样式class用作主题 | `jv-light` | +| `expanded` | 默认展开视图 | `false` | +| `timeformat` | 自定义时间格式函数 | time => time.toLocaleString() | ## 主题 diff --git a/example/app.js b/example/app.js index 8aec4bb..4b53d83 100644 --- a/example/app.js +++ b/example/app.js @@ -27,6 +27,7 @@ new Vue({ copiedText: '复制成功' }} boxed + timeformat={time => new Date(time)} sort>
value.toLocaleString(), + } }, provide () { return { expandDepth: this.expandDepth, + timeformat: this.timeformat, } }, data () { @@ -93,11 +98,6 @@ export default { expandCode: this.expanded } }, - watch: { - value() { - this.onResized() - } - }, computed: { jvClass() { return 'jv-container ' + this.theme + (this.boxed ? ' boxed' : '') @@ -112,6 +112,11 @@ export default { } } }, + watch: { + value() { + this.onResized() + } + }, mounted: function () { this.debounceResized = debounce(this.debResized.bind(this), 200); if (this.boxed && this.$refs.jsonBox) { diff --git a/lib/types/json-array.vue b/lib/types/json-array.vue index 4fd15a5..633fa67 100644 --- a/lib/types/json-array.vue +++ b/lib/types/json-array.vue @@ -3,11 +3,6 @@ import JsonBox from '../json-box' export default { name: 'JsonArray', - data() { - return { - value: [] - } - }, props: { jsonValue: { type: Array, @@ -24,6 +19,11 @@ export default { sort: Boolean, expand: Boolean }, + data() { + return { + value: [] + } + }, watch: { jsonValue(newVal) { this.setValue(newVal); diff --git a/lib/types/json-date.vue b/lib/types/json-date.vue index 80232a7..6b54103 100644 --- a/lib/types/json-date.vue +++ b/lib/types/json-date.vue @@ -1,6 +1,7 @@