mirror of
https://github.com/Luzifer/ots.git
synced 2024-07-01 16:41:23 +00:00
48 lines
893 B
Vue
48 lines
893 B
Vue
![]() |
<template>
|
||
|
<button
|
||
|
v-if="hasClipboard"
|
||
|
:class="{'btn': true, 'btn-primary': !copyToClipboardSuccess, 'btn-success': copyToClipboardSuccess}"
|
||
|
:disabled="!content"
|
||
|
@click="copy"
|
||
|
>
|
||
|
<i class="fas fa-clipboard" />
|
||
|
</button>
|
||
|
</template>
|
||
|
<script>
|
||
|
export default {
|
||
|
computed: {
|
||
|
hasClipboard() {
|
||
|
return Boolean(navigator.clipboard && navigator.clipboard.writeText)
|
||
|
},
|
||
|
},
|
||
|
|
||
|
data() {
|
||
|
return {
|
||
|
copyToClipboardSuccess: false,
|
||
|
}
|
||
|
},
|
||
|
|
||
|
methods: {
|
||
|
copy() {
|
||
|
navigator.clipboard.writeText(this.content)
|
||
|
.then(() => {
|
||
|
this.copyToClipboardSuccess = true
|
||
|
window.setTimeout(() => {
|
||
|
this.copyToClipboardSuccess = false
|
||
|
}, 500)
|
||
|
})
|
||
|
},
|
||
|
},
|
||
|
|
||
|
name: 'AppClipboardButton',
|
||
|
|
||
|
props: {
|
||
|
content: {
|
||
|
default: null,
|
||
|
required: false,
|
||
|
type: String,
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
</script>
|