mirror of
https://github.com/tenrok/vue-json-viewer.git
synced 2026-06-23 20:40:38 +03:00
add icon prefix
This commit is contained in:
+2
-1
@@ -16,7 +16,8 @@ new Vue({
|
|||||||
a: 1
|
a: 1
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
showCopy: true
|
showCopy: true,
|
||||||
|
iconPrefix: 'ive-'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
+4
-2
@@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="node">
|
<div class="node">
|
||||||
<span class="key" v-if="keyName">
|
<span class="key" v-if="keyName">
|
||||||
<i class="icon" v-if="isObject" :class="{'ion-arrow-down-b': toggle, 'ion-arrow-up-b': !toggle}" @click.stop="toggleNode"></i>
|
<j-icon v-if="isObject" :type="value ? 'ion-arrow-down-b' : 'ion-arrow-up-b'" @click.stop="toggleNode"></j-icon>
|
||||||
{{keyName}}:
|
{{keyName}}:
|
||||||
</span>
|
</span>
|
||||||
<commponent :is="`Json${valueType}`" :json-value="value" v-model="toggle" :key-name="keyName"></commponent>
|
<commponent :is="`Json${valueType}`" :json-value="value" v-model="toggle" :key-name="keyName"></commponent>
|
||||||
@@ -9,6 +9,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import JIcon from './json-icon'
|
||||||
import JsonString from './types/json-string';
|
import JsonString from './types/json-string';
|
||||||
import JsonNumber from './types/json-number';
|
import JsonNumber from './types/json-number';
|
||||||
import JsonBoolean from './types/json-boolean';
|
import JsonBoolean from './types/json-boolean';
|
||||||
@@ -54,7 +55,8 @@ export default {
|
|||||||
JsonNumber,
|
JsonNumber,
|
||||||
JsonBoolean,
|
JsonBoolean,
|
||||||
JsonObject,
|
JsonObject,
|
||||||
JsonArray
|
JsonArray,
|
||||||
|
JIcon
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<template>
|
||||||
|
<i :class="{
|
||||||
|
[`${iconPrefix}icon`]: true,
|
||||||
|
[`${iconPrefix}${type}`]: true
|
||||||
|
}" @click="iconClick"></i>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
name: 'JsonIcon',
|
||||||
|
inject: ['iconPrefix'],
|
||||||
|
props: {
|
||||||
|
iconPrefix: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
type: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
iconClick(e) {
|
||||||
|
this.$emit('click', e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
+20
-6
@@ -1,21 +1,22 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="json-viewer">
|
<div class="json-viewer">
|
||||||
<div class="tooltip">
|
<div class="tooltip">
|
||||||
<i class="icon ion-qr-scanner" @click.native="bigger" v-if="showBigger"></i>
|
<j-icon v-if="showBigger" type="ion-qr-scanner" @click="bigger"></j-icon>
|
||||||
<i class="icon ion-checkmark copied" v-if="copied"></i>
|
<j-icon v-if="copied" class="copied" type="ion-checkmark"></j-icon>
|
||||||
<i class="icon ion-md-clipboard copy" @click.native="clip" v-if="showCopy && !copied"></i>
|
<j-icon v-if="showCopy && !copied" class="copy" type="ion-md-clipboard" @click="clip"></j-icon>
|
||||||
</div>
|
</div>
|
||||||
<div class="code-box" :class="{'more': moreCode}">
|
<div class="code-box" :class="{'more': moreCode}">
|
||||||
<json-box :value="value" :key-name="keyName"></json-box>
|
<json-box :value="value" :key-name="keyName"></json-box>
|
||||||
</div>
|
</div>
|
||||||
<div class="more-code" @click="toggleMoreCode">
|
<div class="more-code" @click="toggleMoreCode">
|
||||||
<i class="icon" :class="{'ion-ios-arrow-up': moreCode, 'ion-ios-arrow-down': !moreCode}"></i>
|
<j-icon :type="moreCode ? 'ion-ios-arrow-up' : 'ion-ios-arrow-down'"></j-icon>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import Vue from 'vue';
|
import Vue from 'vue';
|
||||||
|
import JIcon from './json-icon'
|
||||||
import JsonBox from './json-box';
|
import JsonBox from './json-box';
|
||||||
import Clipboard from 'clipboard';
|
import Clipboard from 'clipboard';
|
||||||
|
|
||||||
@@ -33,6 +34,15 @@ export default {
|
|||||||
showBigger: {
|
showBigger: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false
|
default: false
|
||||||
|
},
|
||||||
|
iconPrefix: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
}
|
||||||
|
},
|
||||||
|
provide() {
|
||||||
|
return {
|
||||||
|
iconPrefix: this.iconPrefix
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
@@ -46,7 +56,7 @@ export default {
|
|||||||
clip() {
|
clip() {
|
||||||
const clipBoard = new Clipboard('.copy', {
|
const clipBoard = new Clipboard('.copy', {
|
||||||
text: () => {
|
text: () => {
|
||||||
return JSON.stringify(this.$attrs.value, null, 2);
|
return JSON.stringify(this.value, null, 2);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -55,7 +65,7 @@ export default {
|
|||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.copied = false;
|
this.copied = false;
|
||||||
}, 2000);
|
}, 2000);
|
||||||
this.$Message.success('Code copied');
|
this.$emit('copied');
|
||||||
clipBoard.destroy();
|
clipBoard.destroy();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -65,6 +75,10 @@ export default {
|
|||||||
toggleMoreCode() {
|
toggleMoreCode() {
|
||||||
this.moreCode = !this.moreCode;
|
this.moreCode = !this.moreCode;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
components: {
|
||||||
|
JsonBox,
|
||||||
|
JIcon
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<span>
|
<span>
|
||||||
<i v-if="!keyName" class="icon" :class="{'ion-arrow-down-b': value, 'ion-arrow-up-b': !value}" @click.stop="toggle"></i>
|
<j-icon v-if="!keyName" :type="value ? 'ion-arrow-down-b' : 'ion-arrow-up-b'" @click.stop="toggle"></j-icon>
|
||||||
<span>[</span>
|
<span>[</span>
|
||||||
<template v-if="jsonValue.length">
|
<template v-if="jsonValue.length">
|
||||||
<json-box v-show="value" v-for="(val, index) in jsonValue" :key="index" :value="val"></json-box>
|
<json-box v-show="value" v-for="(val, index) in jsonValue" :key="index" :value="val"></json-box>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<span>
|
<span>
|
||||||
<i v-if="!keyName" class="icon" :class="{'ion-arrow-down-b': value, 'ion-arrow-up-b': !value}" @click.stop="toggle"></i>
|
<j-icon v-if="!keyName" :type="value ? 'ion-arrow-down-b' : 'ion-arrow-up-b'" @click.stop="toggle"></j-icon>
|
||||||
<span>{</span>
|
<span>{</span>
|
||||||
<template v-if="Object.keys(jsonValue).length">
|
<template v-if="Object.keys(jsonValue).length">
|
||||||
<json-box v-show="value" v-for="(v, k) in jsonValue" :key="k" :key-name="k" :value="v"></json-box>
|
<json-box v-show="value" v-for="(v, k) in jsonValue" :key="k" :key-name="k" :value="v"></json-box>
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import JIcon from '../json-icon'
|
||||||
export default {
|
export default {
|
||||||
name: 'JsonObject',
|
name: 'JsonObject',
|
||||||
props: {
|
props: {
|
||||||
@@ -23,6 +24,9 @@ export default {
|
|||||||
console.log('toggle')
|
console.log('toggle')
|
||||||
this.$emit('input', !this.value);
|
this.$emit('input', !this.value);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
components: {
|
||||||
|
JIcon
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user