forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCopyButton.vue
More file actions
61 lines (54 loc) · 1.07 KB
/
CopyButton.vue
File metadata and controls
61 lines (54 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<template lang="pug">
.relative
q-btn(
color="primary"
round
dense
flat
:icon="mdiContentCopy"
@click="copy"
)
q-tooltip Copy to Clipboard
transition(
enter-active-class="animated fadeIn"
leave-active-class="animated fadeOut"
)
q-badge.absolute(
v-show="copied"
style="top: 8px; right: 58px;"
) Copied to clipboard
</template>
<script>
import { copyToClipboard } from 'quasar'
import { mdiContentCopy } from '@quasar/extras/mdi-v4'
export default {
props: {
text: [ Function, String ]
},
created () {
this.mdiContentCopy = mdiContentCopy
},
data () {
return {
copied: false
}
},
methods: {
copy () {
const text = typeof this.text === 'function'
? this.text()
: this.text
copyToClipboard(text)
.then(() => {
this.copied = true
clearTimeout(this.timer)
this.timer = setTimeout(() => {
this.copied = false
this.timer = null
}, 2000)
})
.catch(() => {})
}
}
}
</script>