mirror of
https://github.com/tenrok/vue-json-viewer.git
synced 2026-06-23 20:40:38 +03:00
highlight links & fix some issue
This commit is contained in:
+2
-1
@@ -1,5 +1,5 @@
|
|||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
import JsonViewer from '../vue-json-viewer'
|
import JsonViewer from '../lib'
|
||||||
|
|
||||||
Vue.use(JsonViewer)
|
Vue.use(JsonViewer)
|
||||||
|
|
||||||
@@ -34,6 +34,7 @@ new Vue({
|
|||||||
{
|
{
|
||||||
id: '5968fcad629fa84ab65a5247',
|
id: '5968fcad629fa84ab65a5247',
|
||||||
firstname: 'Ada',
|
firstname: 'Ada',
|
||||||
|
link: 'http://google.com',
|
||||||
lastname: 'Lovelace',
|
lastname: 'Lovelace',
|
||||||
awards: null,
|
awards: null,
|
||||||
known: [
|
known: [
|
||||||
|
|||||||
+17
-18
@@ -8,7 +8,6 @@
|
|||||||
ref="clip"
|
ref="clip"
|
||||||
class="jv-button"
|
class="jv-button"
|
||||||
:class="{copied}"
|
:class="{copied}"
|
||||||
@click="clip"
|
|
||||||
>{{ copied ? 'copied!' : 'copy' }}</span>
|
>{{ copied ? 'copied!' : 'copy' }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
@@ -97,6 +96,16 @@ export default {
|
|||||||
this.onResized()
|
this.onResized()
|
||||||
this.$refs.jsonBox.$el.addEventListener("resized", this.onResized, true)
|
this.$refs.jsonBox.$el.addEventListener("resized", this.onResized, true)
|
||||||
}
|
}
|
||||||
|
if (this.copyable) {
|
||||||
|
const clipBoard = new Clipboard(this.$refs.clip, {
|
||||||
|
text: () => {
|
||||||
|
return JSON.stringify(this.value, null, 2)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
clipBoard.on('success', () => {
|
||||||
|
this.onCopied()
|
||||||
|
})
|
||||||
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
onResized () {
|
onResized () {
|
||||||
@@ -108,25 +117,15 @@ export default {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
clip () {
|
onCopied() {
|
||||||
if (this.copied) {
|
if (this.copied) {
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
|
this.copied = true
|
||||||
const clipBoard = new Clipboard(this.$refs.clip, {
|
setTimeout(() => {
|
||||||
text: () => {
|
this.copied = false
|
||||||
return JSON.stringify(this.value, null, 2)
|
}, 2000)
|
||||||
}
|
this.$emit('copied')
|
||||||
})
|
|
||||||
|
|
||||||
clipBoard.on('success', () => {
|
|
||||||
this.copied = true
|
|
||||||
setTimeout(() => {
|
|
||||||
this.copied = false
|
|
||||||
}, 2000)
|
|
||||||
this.$emit('copied')
|
|
||||||
clipBoard.destroy()
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
toggleExpandCode () {
|
toggleExpandCode () {
|
||||||
this.expandCode = !this.expandCode
|
this.expandCode = !this.expandCode
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const ordered = {}
|
const ordered = {}
|
||||||
Object.keys(this.jsonValue).sort().forEach(key => {
|
Object.keys(this.jsonValue).forEach(key => {
|
||||||
ordered[key] = this.jsonValue[key]
|
ordered[key] = this.jsonValue[key]
|
||||||
})
|
})
|
||||||
return ordered
|
return ordered
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
<script>
|
<script>
|
||||||
|
const REG_LINK = /^\w+:\/\//;
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'JsonString',
|
name: 'JsonString',
|
||||||
functional: true,
|
functional: true,
|
||||||
@@ -9,13 +11,19 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
render (h, { props }) {
|
render (h, { props }) {
|
||||||
|
let value = props.jsonValue;
|
||||||
|
|
||||||
|
if (REG_LINK.test(value)) {
|
||||||
|
value = `<a href="${value}" target="_blank" style="color: #0366d6;">${value}</a>`;
|
||||||
|
}
|
||||||
|
|
||||||
return h('span', {
|
return h('span', {
|
||||||
class: {
|
class: {
|
||||||
'jv-item': true,
|
'jv-item': true,
|
||||||
'jv-string': true,
|
'jv-string': true,
|
||||||
},
|
},
|
||||||
domProps: {
|
domProps: {
|
||||||
innerHTML: `"${props.jsonValue.toString()}"`
|
innerHTML: `"${value.toString()}"`
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "vue-json-viewer",
|
"name": "vue-json-viewer",
|
||||||
"version": "2.1.5",
|
"version": "2.1.6",
|
||||||
"description": "vuejs展示json的组件",
|
"description": "vuejs展示json的组件",
|
||||||
"main": "vue-json-viewer.js",
|
"main": "vue-json-viewer.js",
|
||||||
"files": [
|
"files": [
|
||||||
|
|||||||
Reference in New Issue
Block a user