mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-04-21 23:36:15 -04:00
18 lines
450 B
TypeScript
18 lines
450 B
TypeScript
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
|
|
}
|
|
|
|
export const copyable = {
|
|
methods: {
|
|
copy(text: string, toastText = 'Copied to clipboard !') {
|
|
copyToClipboard(text)
|
|
this.$toast.success(toastText)
|
|
}
|
|
}
|
|
}
|