mirror of
https://github.com/tenrok/vue-json-viewer.git
synced 2026-06-23 20:40:38 +03:00
add support for 'function' values in json objects
This commit is contained in:
@@ -4,19 +4,19 @@ Simple json display component, based on vue
|
|||||||
|
|
||||||
## Installing:
|
## Installing:
|
||||||
Using npm:
|
Using npm:
|
||||||
```
|
```
|
||||||
$ npm install vue-json-viewer
|
$ npm install vue-json-viewer
|
||||||
```
|
```
|
||||||
Using bower:
|
Using bower:
|
||||||
|
|
||||||
|
|
||||||
```
|
```
|
||||||
$ yarn add vue-json-viewer
|
$ yarn add vue-json-viewer
|
||||||
```
|
```
|
||||||
|
|
||||||
## Example:
|
## Example:
|
||||||
|
|
||||||
``` html
|
``` html
|
||||||
<json-viewer :value="jsonData" :show-copy="true" icon-prefix="ion" :show-bigger="true"></json-viewer>
|
<json-viewer :value="jsonData" :show-copy="true" icon-prefix="ion" :show-bigger="true"></json-viewer>
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -31,6 +31,7 @@ export default {
|
|||||||
{key: 'hello word'},
|
{key: 'hello word'},
|
||||||
],
|
],
|
||||||
val: {
|
val: {
|
||||||
|
c: () = {},
|
||||||
b: 'a',
|
b: 'a',
|
||||||
a: 'hello word',
|
a: 'hello word',
|
||||||
asd2: 1,
|
asd2: 1,
|
||||||
@@ -42,12 +43,12 @@ export default {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
## Result:
|
## Result:
|
||||||

|

|
||||||
|
|
||||||
|
|
||||||
## Options:
|
## Options:
|
||||||
|
|
||||||
| Property | Description |
|
| Property | Description |
|
||||||
| ----------- |:-------------|
|
| ----------- |:-------------|
|
||||||
| value | json data |
|
| value | json data |
|
||||||
| show-copy | display the copy button |
|
| show-copy | display the copy button |
|
||||||
|
|||||||
+2
-1
@@ -12,6 +12,7 @@ new Vue({
|
|||||||
{key: 'hello word'},
|
{key: 'hello word'},
|
||||||
],
|
],
|
||||||
val: {
|
val: {
|
||||||
|
c: () = {},
|
||||||
b: 'a',
|
b: 'a',
|
||||||
a: 'hello word',
|
a: 'hello word',
|
||||||
asd2: 1,
|
asd2: 1,
|
||||||
@@ -21,4 +22,4 @@ new Vue({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
components: {JsonViewer}
|
components: {JsonViewer}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import JsonNumber from './types/json-number';
|
|||||||
import JsonBoolean from './types/json-boolean';
|
import JsonBoolean from './types/json-boolean';
|
||||||
import JsonObject from './types/json-object';
|
import JsonObject from './types/json-object';
|
||||||
import JsonArray from './types/json-array';
|
import JsonArray from './types/json-array';
|
||||||
|
import JsonFunction from './types/json-function';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'JsonBox',
|
name: 'JsonBox',
|
||||||
@@ -44,6 +45,8 @@ export default {
|
|||||||
return 'String';
|
return 'String';
|
||||||
} else if (typeof this.value === 'boolean') {
|
} else if (typeof this.value === 'boolean') {
|
||||||
return 'Boolean';
|
return 'Boolean';
|
||||||
|
} else if (typeof this.value === 'function') {
|
||||||
|
return 'Function';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
isObject() {
|
isObject() {
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<template>
|
||||||
|
<span class="json-function"><function></span>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
name: 'JsonFunction',
|
||||||
|
props: {
|
||||||
|
jsonValue: Function
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
.json-function {
|
||||||
|
color: #067bca;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
Reference in New Issue
Block a user