mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-04-22 07:46:15 -04:00
19 lines
522 B
TypeScript
19 lines
522 B
TypeScript
import {Component, Vue} from 'nuxt-property-decorator'
|
|
|
|
const copyToClipboard = (text: string) => {
|
|
const input = document.createElement('textarea')
|
|
input.innerHTML = text
|
|
document.body.appendChild(input)
|
|
input.select()
|
|
const result = document.execCommand('copy')
|
|
document.body.removeChild(input)
|
|
return result
|
|
}
|
|
|
|
@Component
|
|
export class CopyableMixin extends Vue {
|
|
copy(text: string|number, toastText = 'Copied to clipboard !') {
|
|
copyToClipboard(String(text))
|
|
this.$toast.success(toastText)
|
|
}
|
|
}
|