This is fork from egoist/v-copy and now support Vue 3.
Vue directive to copy to clipboard.
yarn add vue3-copy
First register the directive globally:
import Copy from "vue3-copy";
const app = createApp(App);
app.use(Copy);
app.mount("#app");
Then use it in template:
<template>
<button v-copy="`some text`">Copy!</button>
</template>
v-copy:callback
: executed after text is copied to clipboard.
<template>
<button v-copy="`some text`" v-copy:callback="handleCopied">Copy!</button>
</template>
<script>
export default {
setup() {
function handleCopied(text = "") {
alert(`Copied: ${text}`)
}
return {
handleCopied
}
}
}
</script>
This supports what copy-text-to-clipboard supports, namely ever-green browsers and IE9+. (Not all are carefully tested though :P)
MIT © EGOIST