yarn add vue-clipboard3
or
npm install --save vue-clipboard3
<template lang="html">
<div>
<input type="text" v-model="text">
<button @click="copy">Copy!</button>
</div>
</template>
<script lang="ts">
import { defineComponent, ref } from '@vue/composition-api'
import useClipboard from 'vue-clipboard3'
export default defineComponent({
setup() {
const { toClipboard } = useClipboard()
const text = ref('')
const copy = async () => {
try {
await toClipboard(text.value)
console.log('Copied to clipboard')
} catch (e) {
console.error(e)
}
}
return { copy, text }
}
})
</script>