2
0
mirror of https://github.com/tenrok/vue-json-viewer.git synced 2026-06-23 20:40:38 +03:00

feat: support customize copy text

This commit is contained in:
陈峰
2019-08-31 17:15:51 +08:00
parent fae9735acb
commit c0a26557e0
4 changed files with 17 additions and 6 deletions
+1 -1
View File
@@ -145,7 +145,7 @@ import 'vue-json-viewer/style.css'
| ----------- |:------------- | ----------- | | ----------- |:------------- | ----------- |
| `value` | JSON data (can be used with `v-model`) | **Required** | | `value` | JSON data (can be used with `v-model`) | **Required** |
| `expand-depth` | Collapse blocs under this depth | `1` | | `expand-depth` | Collapse blocs under this depth | `1` |
| `copyable` | Display the copy button | `false` | | `copyable` | Display the copy button, you can customize copy text just set `{copyText: 'copy', copiedText: 'copied'}` or set `true` use default copytext | `false` |
| `sort` | Sort keys before displaying | `false` | | `sort` | Sort keys before displaying | `false` |
| `boxed` | Add a fancy "boxed" style to component | `false` | | `boxed` | Add a fancy "boxed" style to component | `false` |
| `theme` | Add a custom CSS class for theming purposes | `jv-light` | | `theme` | Add a custom CSS class for theming purposes | `jv-light` |
+1 -1
View File
@@ -141,7 +141,7 @@ import 'vue-json-viewer/style.css'
| ----------- |:------------- | ----------- | | ----------- |:------------- | ----------- |
| `value` | json对象的值,可以使用v-model,支持响应式 | **必填** | | `value` | json对象的值,可以使用v-model,支持响应式 | **必填** |
| `expand-depth` | 默认展开的层级 | `1` | | `expand-depth` | 默认展开的层级 | `1` |
| `copyable` | 展示复制按钮 | `false` | | `copyable` | 展示复制按钮,默认文案为:copy、copied!, 你可以设置一个对象`{copyText: 'copy', copiedText: 'copied'}` 来自定义复制按钮文案 | `false` |
| `sort` | 按照key排序展示 | `false` | | `sort` | 按照key排序展示 | `false` |
| `boxed` | 为组件添加一个盒样式 | `false` | | `boxed` | 为组件添加一个盒样式 | `false` |
| `theme` | 添加一个自定义的样式class用作主题 | `jv-light` | | `theme` | 添加一个自定义的样式class用作主题 | `jv-light` |
+4 -1
View File
@@ -13,7 +13,10 @@ new Vue({
<json-viewer <json-viewer
value={this.jsonData} value={this.jsonData}
expand-depth={5} expand-depth={5}
copyable copyable={{
copyText: '复制',
copiedText: '复制成功'
}}
boxed boxed
sort></json-viewer> sort></json-viewer>
</div> </div>
+10 -2
View File
@@ -8,7 +8,7 @@
ref="clip" ref="clip"
class="jv-button" class="jv-button"
:class="{copied}" :class="{copied}"
>{{ copied ? 'copied!' : 'copy' }}</span> >{{ copied ? copyText.copiedText : copyText.copyText }}</span>
</div> </div>
<div <div
class="jv-code" class="jv-code"
@@ -54,7 +54,7 @@ export default {
default: 1 default: 1
}, },
copyable: { copyable: {
type: Boolean, type: [Boolean, Object],
default: false default: false
}, },
sort: { sort: {
@@ -90,6 +90,14 @@ export default {
computed: { computed: {
jvClass() { jvClass() {
return 'jv-container ' + this.theme + (this.boxed ? ' boxed' : '') return 'jv-container ' + this.theme + (this.boxed ? ' boxed' : '')
},
copyText() {
const { copyText, copiedText } = this.copyable
return {
copyText: copyText || 'copy',
copiedText: copiedText || 'copied!'
}
} }
}, },
mounted: function () { mounted: function () {