A Compoent for Vue 2 & 3 base on clipboard.js.
If you think it's good , give me a star.Thanks.
yarn add @maybecode/v-clipboard
yarn add @maybecode/v-clipboard @vue/composition-api
import { createApp } from 'vue';
import VClipboard from '@maybecode/v-clipboard'
import '@maybecode/v-clipboard/dist-lib/style.css'
const app = createApp();
app.use(VClipboard);
import Vue from 'vue';
import VClipboard from '@maybecode/v-clipboard'
import '@maybecode/v-clipboard/dist-lib/style.css'
Vue.use(VClipboard);
<template>
<v-clipboard text="text 1" @success="onSuccess">text 1</v-clipboard>
</template>
<script lang="ts" setup>
import { ref } from 'vue';
import VClipboard, { SuccessCallback, Config } from '@maybecode/v-clipboard'
import '@maybecode/v-clipboard/dist-lib/style.css'
const config = ref<Config>({})
const clipboard = ref<VClipboard>();
const clickCopy = () => {
clipboard.value?.clickCopy();
}
const onSuccess: SuccessCallback = (e,c) => {
alert(`Copy ${e.text} succeeded!`);
}
name | type | default | remark |
---|---|---|---|
config | {} | clipboard.js Options |
|
btnText | string | Copy | copy button text |
name | type |
---|---|
success | (e: Event,cbjs: ClipboardJS) => void |
error | (e: Event,cbjs: ClipboardJS) => void |
name | explain |
---|---|
default | content |
trigger | custom trigger element |
name | explain | params |
---|---|---|
clickCopy | Click to trigger copy | - |
Edge |
Firefox |
Chrome |
Safari |
---|---|---|---|
Edge | last 2 versions | last 2 versions | last 2 versions |