2
0
mirror of https://github.com/tenrok/vue-json-viewer.git synced 2026-06-14 18:42:31 +03:00

feat: support long string expand

This commit is contained in:
风棋
2020-11-13 11:40:05 +08:00
parent febc8e5d00
commit 3b056e2079
3 changed files with 73 additions and 23 deletions
+5 -1
View File
@@ -1,4 +1,8 @@
## 2.2.14 2020-10-13
## 2.2.16 2020-11-13
- support long string expand [issues](https://github.com/chenfengjw163/vue-json-viewer/issues/60)
## 2.2.15 2020-10-13
- Add Preview Mode
+67 -21
View File
@@ -3,38 +3,84 @@ const REG_LINK = /^\w+:\/\//;
export default {
name: 'JsonString',
functional: true,
props: {
jsonValue: {
type: String,
required: true
}
},
render (h, { props }) {
let value = props.jsonValue;
data() {
return {
expand: false,
canExtend: false,
}
},
mounted() {
if (this.$refs.itemRef.offsetHeight > this.$refs.holderRef.offsetHeight) {
this.canExtend = true;
}
},
methods: {
toggle() {
this.expand = !this.expand;
}
},
render (h) {
let value = this.jsonValue;
const islink = REG_LINK.test(value)
let domProps
if (islink) {
value = `<a href="${value}" target="_blank" style="color: #0366d6;">${value}</a>`;
domProps = {
innerHTML: `"${value.toString()}"`
}
let domItem
if (this.expand) {
domItem = {
class: {
'jv-ellipsis': true,
},
on: {
click: this.toggle
},
domProps: {
innerText: '...'
}
};
} else {
domProps = {
innerText: `"${value.toString()}"`
domItem = {
class: {
'jv-item': true,
'jv-string': true,
},
ref: 'itemRef',
}
if (islink) {
value = `<a href="${value}" target="_blank" style="color: #0366d6;">${value}</a>`;
domItem.domProps = {
innerHTML: `"${value.toString()}"`
}
} else {
domItem.domProps = {
innerText: `"${value.toString()}"`
}
}
}
return h('span', {
class: {
'jv-item': true,
'jv-string': true,
},
domProps: {
...domProps
}
})
return h('span', {}, [
this.canExtend && h('span', {
class: {
'jv-toggle': true,
open: this.expand,
},
on: {
click: this.toggle,
}
}),
h('span', {
class: {
'jv-holder-node': true,
},
ref: 'holderRef'
}),
h('span', domItem)
])
}
}
</script>
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "vue-json-viewer",
"version": "2.2.15",
"version": "2.2.16",
"description": "vuejs展示json的组件",
"main": "vue-json-viewer.js",
"files": [