diff --git a/README.md b/README.md
index 4657c7a..16602a1 100644
--- a/README.md
+++ b/README.md
@@ -4,20 +4,25 @@ Simple json display component, based on vue
## Installing:
Using npm:
-```
+```
$ npm install vue-json-viewer
```
Using bower:
-```
+```
$ yarn add vue-json-viewer
```
## Example:
-``` html
-
+``` html
+
```
``` js
@@ -42,14 +47,15 @@ export default {
}
```
## Result:
-
+
## Options:
-| Property | Description |
-| ----------- |:-------------|
-| value | json data |
-| show-copy | display the copy button |
-| show-bigger | display the bigger button |
-| icon-prefix | Custom Font icon prefix |
+| Property | Description |
+| ----------- |:------------- |
+| value | json data |
+| show-copy | display the copy button |
+| show-bigger | display the bigger button |
+| icon-prefix | Custom Font icon prefix |
+| sort-keys | Sort items by key names |
diff --git a/json-box.vue b/json-box.vue
index 9857f48..f806b87 100644
--- a/json-box.vue
+++ b/json-box.vue
@@ -4,7 +4,7 @@
{{keyName}}:
-
+
@@ -20,7 +20,8 @@ export default {
name: 'JsonBox',
props: {
value: [Object, Array, String, Number, Boolean],
- keyName: String
+ keyName: String,
+ sortKeys: Boolean
},
data() {
return {
diff --git a/json-viewer.vue b/json-viewer.vue
index 0b22c1b..47d17a2 100644
--- a/json-viewer.vue
+++ b/json-viewer.vue
@@ -6,7 +6,7 @@
-
+
@@ -38,6 +38,10 @@ export default {
iconPrefix: {
type: String,
default: ''
+ },
+ sortKeys: {
+ type: Boolean,
+ default: true
}
},
provide() {
@@ -105,7 +109,7 @@ export default {
margin-bottom: 15px;
}
}
-
+
.more-code {
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
position: absolute;
@@ -148,7 +152,7 @@ export default {
font-size: 18px;
}
}
-
+
.j-icon {
font-size: 12px;
}
diff --git a/types/json-object.vue b/types/json-object.vue
index 96c0136..9fb9795 100644
--- a/types/json-object.vue
+++ b/types/json-object.vue
@@ -2,8 +2,8 @@
{
-
-
+
+
...
}
@@ -17,7 +17,19 @@ export default {
props: {
jsonValue: Object,
keyName: String,
- value: Boolean
+ value: Boolean,
+ sortKeys: Boolean
+ },
+ computed: {
+ ordered () {
+ const ordered = {};
+ if (this.sortKeys) {
+ Object.keys(this.jsonValue).sort().forEach(function(key) {
+ ordered[key] = this.jsonValue[key];
+ });
+ }
+ return ordered;
+ }
},
methods: {
toggle() {