mirror of
https://github.com/tenrok/vue-json-viewer.git
synced 2026-06-23 20:40:38 +03:00
feat: add timeformat props
This commit is contained in:
@@ -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)
|
||||||
@@ -152,6 +152,7 @@ import 'vue-json-viewer/style.css'
|
|||||||
| `boxed` | Add a fancy "boxed" style to component | `false` |
|
| `boxed` | Add a fancy "boxed" style to component | `false` |
|
||||||
| `theme` | Add a custom CSS class for theming purposes | `jv-light` |
|
| `theme` | Add a custom CSS class for theming purposes | `jv-light` |
|
||||||
| `expanded` | Default expand the view | `false` |
|
| `expanded` | Default expand the view | `false` |
|
||||||
|
| `timeformat` | custom time format function | time => time.toLocaleString() |
|
||||||
|
|
||||||
## Listeners
|
## Listeners
|
||||||
|
|
||||||
|
|||||||
@@ -145,6 +145,8 @@ import 'vue-json-viewer/style.css'
|
|||||||
| `sort` | 按照key排序展示 | `false` |
|
| `sort` | 按照key排序展示 | `false` |
|
||||||
| `boxed` | 为组件添加一个盒样式 | `false` |
|
| `boxed` | 为组件添加一个盒样式 | `false` |
|
||||||
| `theme` | 添加一个自定义的样式class用作主题 | `jv-light` |
|
| `theme` | 添加一个自定义的样式class用作主题 | `jv-light` |
|
||||||
|
| `expanded` | 默认展开视图 | `false` |
|
||||||
|
| `timeformat` | 自定义时间格式函数 | time => time.toLocaleString() |
|
||||||
|
|
||||||
## 主题
|
## 主题
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ new Vue({
|
|||||||
copiedText: '复制成功'
|
copiedText: '复制成功'
|
||||||
}}
|
}}
|
||||||
boxed
|
boxed
|
||||||
|
timeformat={time => new Date(time)}
|
||||||
sort></json-viewer>
|
sort></json-viewer>
|
||||||
<hr />
|
<hr />
|
||||||
<json-viewer
|
<json-viewer
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
devtool: 'cheap-module-source-map',
|
devtool: 'cheap-module-source-map',
|
||||||
devServer: {
|
devServer: {
|
||||||
port: 8081,
|
port: 8082,
|
||||||
disableHostCheck: true
|
disableHostCheck: true
|
||||||
},
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
|
|||||||
+10
-5
@@ -80,10 +80,15 @@ export default {
|
|||||||
type: String,
|
type: String,
|
||||||
default: 'jv-light'
|
default: 'jv-light'
|
||||||
},
|
},
|
||||||
|
timeformat: {
|
||||||
|
type: Function,
|
||||||
|
default: value => value.toLocaleString(),
|
||||||
|
}
|
||||||
},
|
},
|
||||||
provide () {
|
provide () {
|
||||||
return {
|
return {
|
||||||
expandDepth: this.expandDepth,
|
expandDepth: this.expandDepth,
|
||||||
|
timeformat: this.timeformat,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data () {
|
data () {
|
||||||
@@ -93,11 +98,6 @@ export default {
|
|||||||
expandCode: this.expanded
|
expandCode: this.expanded
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
|
||||||
value() {
|
|
||||||
this.onResized()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: {
|
computed: {
|
||||||
jvClass() {
|
jvClass() {
|
||||||
return 'jv-container ' + this.theme + (this.boxed ? ' boxed' : '')
|
return 'jv-container ' + this.theme + (this.boxed ? ' boxed' : '')
|
||||||
@@ -112,6 +112,11 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
watch: {
|
||||||
|
value() {
|
||||||
|
this.onResized()
|
||||||
|
}
|
||||||
|
},
|
||||||
mounted: function () {
|
mounted: function () {
|
||||||
this.debounceResized = debounce(this.debResized.bind(this), 200);
|
this.debounceResized = debounce(this.debResized.bind(this), 200);
|
||||||
if (this.boxed && this.$refs.jsonBox) {
|
if (this.boxed && this.$refs.jsonBox) {
|
||||||
|
|||||||
@@ -3,11 +3,6 @@ import JsonBox from '../json-box'
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'JsonArray',
|
name: 'JsonArray',
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
value: []
|
|
||||||
}
|
|
||||||
},
|
|
||||||
props: {
|
props: {
|
||||||
jsonValue: {
|
jsonValue: {
|
||||||
type: Array,
|
type: Array,
|
||||||
@@ -24,6 +19,11 @@ export default {
|
|||||||
sort: Boolean,
|
sort: Boolean,
|
||||||
expand: Boolean
|
expand: Boolean
|
||||||
},
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
value: []
|
||||||
|
}
|
||||||
|
},
|
||||||
watch: {
|
watch: {
|
||||||
jsonValue(newVal) {
|
jsonValue(newVal) {
|
||||||
this.setValue(newVal);
|
this.setValue(newVal);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
name: 'JsonDate',
|
name: 'JsonDate',
|
||||||
|
inject: ['timeformat'],
|
||||||
functional: true,
|
functional: true,
|
||||||
props: {
|
props: {
|
||||||
jsonValue: {
|
jsonValue: {
|
||||||
@@ -8,8 +9,9 @@ export default {
|
|||||||
required: true
|
required: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
render (h, { props }) {
|
render (h, { props, injections }) {
|
||||||
const value = props.jsonValue;
|
const value = props.jsonValue;
|
||||||
|
const timeformat = injections.timeformat;
|
||||||
|
|
||||||
return h('span', {
|
return h('span', {
|
||||||
class: {
|
class: {
|
||||||
@@ -17,7 +19,7 @@ export default {
|
|||||||
'jv-string': true,
|
'jv-string': true,
|
||||||
},
|
},
|
||||||
domProps: {
|
domProps: {
|
||||||
innerText: `"${value.toLocaleString()}"`
|
innerText: `"${timeformat(value)}"`
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,6 @@ import JsonBox from '../json-box'
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'JsonObject',
|
name: 'JsonObject',
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
value: {}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
props: {
|
props: {
|
||||||
jsonValue: {
|
jsonValue: {
|
||||||
type: Object,
|
type: Object,
|
||||||
@@ -24,6 +19,11 @@ export default {
|
|||||||
expand: Boolean,
|
expand: Boolean,
|
||||||
sort: Boolean
|
sort: Boolean
|
||||||
},
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
value: {}
|
||||||
|
}
|
||||||
|
},
|
||||||
computed: {
|
computed: {
|
||||||
ordered () {
|
ordered () {
|
||||||
if (!this.sort) {
|
if (!this.sort) {
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "vue-json-viewer",
|
"name": "vue-json-viewer",
|
||||||
"version": "2.2.12",
|
"version": "2.2.13",
|
||||||
"description": "vuejs展示json的组件",
|
"description": "vuejs展示json的组件",
|
||||||
"main": "vue-json-viewer.js",
|
"main": "vue-json-viewer.js",
|
||||||
"files": [
|
"files": [
|
||||||
|
|||||||
Reference in New Issue
Block a user