2.0.0 • Published 2 years ago

vue-clipboard3 v2.0.0

Weekly downloads
224
License
MIT
Repository
github
Last release
2 years ago

vue-clipboard3

Easily copy to clipboard in Vue 3 (composition-api) using clipboard.js 📋

Thanks to vue-clipboard2 for inspiration!

Install

yarn add vue-clipboard3

or

npm install --save vue-clipboard3

About

For use with Vue 3 and the Composition API. I decided to keep in line with the Vue 3 spirit and not make a directive out of this (if you want a vue directive, please make a pull request). I think it makes more sense and provides more clarity to just use this as a method in the setup() function.

Keep it simple.

Usage

Simple

<template lang="html">
  <button @click="copy">Copy!</button>
</template>

<script lang="ts">
import { defineComponent } from '@vue/composition-api'
import useClipboard from 'vue-clipboard3'

export default defineComponent({
  setup() {
    const { toClipboard } = useClipboard()

    const copy = async () => {
      try {
        await toClipboard('Any text you like')
        console.log('Copied to clipboard')
      } catch (e) {
        console.error(e)
      }
    }

    return { copy }
  }
})
</script>

With ref

<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>

API

useClipboard(options: Options)
interface Options {
  /** Fixes IE by appending element to body. Defaults to true. */
  appendToBody: boolean
}

returns an object with a single key: toClipboard

toClipboard(text: string, container?: HTMLElement)

requires that you pass in at least one argument that is a string. This is the text to be copied to the clipboard. The second optional argument is a html element that will be used as the container internally when using clipboard.js.

Contribution

PRs and issues welcome!

git clone https://github.com/JamieCurnow/vue-clipboard3.git
cd vue-clipboard3
yarn install
yarn watch

License

MIT License

el-dialog-hook@tencentcloud/chat-cs-vueashster-vue2-testchat-uikit-vue2@tomer.yechiel/pev2uuikitashster-chat@infinitebrahmanuniverse/nolb-vue-clipfzmtool@ashster/chat-uikit-vueashster-uikit-vue@everything-registry/sub-chunk-3076silvia-testfront-panelgc-chat-webel-drawer-hookeform-designerelg-core-frontendeap-syseap-runtimeef-h5fe-layoutfit2cloud-ui-plushlxd-ui-vue3h-components-nexths-admin-uihs-one-storage-uildp-uilemon-boxfan-createritg-uilive-open-platformlongi-vue3-cliithui-plusjf-ant-vxe-vue3-tsjam-utilslaiyulaiyutestpackage-testmagicbean-saas-commonmanage-layoutmw-td-vnext-liboa-app-uipage-generatorwhhpage-genwhhpage-generator_patchpage-generatorswhhpev2qordialquick-binewtv-ui-3.0runtime-containerresource-managementsbd-core-componentstest-fdttool-test-003sunsun-uivitepress-plugin-awesome-musicplayervue-safe-force-graphvue-safe-force-graph-polarisvue-show-uivue-layout.jsvue-layout3.jsvue-i-componentsvue-loong-uitccc-vue-uikitvirtai-plusvirtai-ui-plusth12123zycloud-uizngue_ts_commonwind-report-vue3-ant3xs_web_uiylcr-template@tencentcloud/chat-uikit-vue@tencentcloud/chat-uikit-vue2@wwtelescope/embed-creator@wltech/hooks@tyrosking/chat-uikit-vue@yakj/y5@yakj/check@zpc_npm/vue-iclient-iconsaallen-testadmin-net-webantdv-business-commonantdv-charts-table@bamboo-assets/vue-next-basic-clipboard@baosight/erx@baosight/erbfox-uiafast-ui@pivoto/ui-base@ifan_tsai/cc-ui@ifan_tsai/cc-ui-test@liuyunxi/antd-extend@liuyunxi/lds-ui@opentiny/tiny-engine-plugin-datasource@opentiny/tiny-engine-plugin-i18n@miitvip/admin-pro@mora-light/vue@lcz-creater/form
2.0.0

2 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago