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

feat: customize copy button with slot and timeout (updated README)

This commit is contained in:
Konstantin Barabanov
2020-03-20 11:03:09 +03:00
parent c4831cc420
commit 57ee6274c7
3 changed files with 47 additions and 9 deletions
+16 -8
View File
@@ -8,7 +8,14 @@
ref="clip"
class="jv-button"
:class="{copied}"
>{{ copied ? copyText.copiedText : copyText.copyText }}</span>
>
<slot
name="copy"
:copied="copied"
>
{{ copied ? copyText.copiedText : copyText.copyText }}
</slot>
</span>
</div>
<div
class="jv-code"
@@ -92,11 +99,12 @@ export default {
return 'jv-container ' + this.theme + (this.boxed ? ' boxed' : '')
},
copyText() {
const { copyText, copiedText } = this.copyable
const { copyText, copiedText, timeout } = this.copyable
return {
copyText: copyText || 'copy',
copiedText: copiedText || 'copied!'
copiedText: copiedText || 'copied!',
timeout: timeout || 2000
}
}
},
@@ -112,8 +120,8 @@ export default {
return JSON.stringify(this.value, null, 2)
}
});
clipBoard.on('success', () => {
this.onCopied()
clipBoard.on('success', (e) => {
this.onCopied(e)
})
}
},
@@ -131,15 +139,15 @@ export default {
}
})
},
onCopied() {
onCopied(copyEvent) {
if (this.copied) {
return;
}
this.copied = true
setTimeout(() => {
this.copied = false
}, 2000)
this.$emit('copied')
}, this.copyText.timeout)
this.$emit('copied', copyEvent)
},
toggleExpandCode () {
this.expandCode = !this.expandCode