Skip to content

Commit 726eea0

Browse files
Merge pull request tylerkrupicka#14 from adierkens/simple-data
Add support for displaying non-objects at top level
2 parents 8136dd0 + 86652ab commit 726eea0

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

harness/App.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
:styles="{ key: '#0977e6' }"
88
v-on:selected="itemSelected"
99
></json-view>
10+
<json-view rootKey="result" data="some string" />
11+
<json-view rootKey="result" :data="2" />
12+
1013
<h5>Events</h5>
1114
<div v-for="(event, index) in events" :key="index">{{ event }}</div>
1215
</div>

src/JSONView.vue

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,16 @@ export default Vue.extend({
115115
},
116116
computed: {
117117
parsed: function(): object {
118-
return this.build(this.rootKey, { ...this.data }, 0, "", true);
118+
if (typeof this.data === "object") {
119+
return this.build(this.rootKey, { ...this.data }, 0, "", true);
120+
}
121+
return {
122+
key: this.rootKey,
123+
type: "value",
124+
path: "",
125+
depth: 0,
126+
value: this.data
127+
};
119128
},
120129
customStyles: function(): object {
121130
const target = {

0 commit comments

Comments
 (0)