2
0
mirror of https://github.com/tenrok/vue-json-viewer.git synced 2026-06-08 17:22:32 +03:00
Files
vue-json-viewer/json-box.vue
T
2018-09-17 06:31:04 +02:00

102 lines
2.5 KiB
Vue
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<div class="node">
<span class="key" v-if="keyName">
<j-icon v-if="isObject" :type="value ? 'arrow-down-b' : 'arrow-up-b'" @click.stop="toggleNode"></j-icon>
{{keyName}}:
</span>
<commponent :is="`Json${valueType}`" :json-value="value" v-model="toggle" :key-name="keyName"></commponent>
</div>
</template>
<script>
import JIcon from './json-icon'
import JsonString from './types/json-string';
import JsonNull from './types/json-null';
import JsonNumber from './types/json-number';
import JsonBoolean from './types/json-boolean';
import JsonObject from './types/json-object';
import JsonArray from './types/json-array';
import JsonFunction from './types/json-function';
export default {
name: 'JsonBox',
props: {
value: [Object, Array, String, Number, Boolean, Function],
keyName: String
},
data() {
return {
toggle: true
};
},
methods: {
toggleNode() {
this.toggle = !this.toggle;
}
},
computed: {
valueType() {
if (this.value === null || this.value === undefined) {
return 'Null';
} else if (Array.isArray(this.value)) {
return 'Array';
} else if (typeof this.value === 'object') {
return 'Object';
} else if (typeof this.value === 'number') {
return 'Number';
} else if (typeof this.value === 'string') {
return 'String';
} else if (typeof this.value === 'boolean') {
return 'Boolean';
} else if (typeof this.value === 'function') {
return 'Function';
}
},
isObject() {
return this.valueType == 'Array' || this.valueType == 'Object'; // eslint-disable-line
}
},
components: {
JsonString,
JsonNumber,
JsonBoolean,
JsonObject,
JsonArray,
JsonFunction,
JsonNull,
JIcon
}
};
</script>
<style lang="scss">
.node {
font-size: 14px;
position: relative;
color: #525252;
font-family: Consolas,Menlo,Courier,monospace;
white-space: nowrap;
&:after {
content: ','
}
&:last-of-type {
&:after {
content: ''
}
}
.j-icon {
position: absolute;
left: -12px;
top: 3px;
color: #80848f;
cursor: pointer;
}
& .node {
margin-left: 25px;
}
}
</style>