v-clipboard

Vue.js Clipboard Plugin
1,101,981 515
Install
npm install v-clipboard@2.2.3
Latest Version:2.2.3
License:MIT
Last Updated:May 4, 2023
Links: GitHub  ·  npm
Maintainer: euvl

npm npm

Vue Clipboard

Demo

https://codesandbox.io/s/epic-waterfall-17yet5?file=/src/App.vue

Install

npm install --save v-clipboard
yarn add v-clipboard
import Vue from 'vue'
import Clipboard from 'v-clipboard'

Vue.use(Clipboard)

Using

When an element that contains v-clipboard directive is clicked, the value of value will be copied into clipboard.


Copying static value (directive should receive actual value):

<button v-clipboard="value">
  Copy to clipboard
</button>
<button v-clipboard="'some text'">
  Copy to clipboard
</button>

Copying dynamic value (directive should recieve a function that returns value):

<button v-clipboard="() => value">
  Copy to clipboard
</button>

Copying anything in your methods:

this.$clipboard(value)

Without plugin:

import { Clipboard } from "v-clipboard"

Clipboard.copy(value)

Events

<button v-clipboard="foo"
        v-clipboard:success="clipboardSuccessHandler"
        v-clipboard:error="clipboardErrorHandler">
  Copy to clipboard
</button>
{
  methods: {
    clipboardSuccessHandler ({ value, event }) {
      console.log('success', value)
    },

    clipboardErrorHandler ({ value, event }) {
      console.log('error', value)
    }
  }
}

Compatibility

Related Packages

vue3-copy

This is fork from egoist/v-copy and now support Vue 3.

1,158 1
@scalar/use-clipboard

tiny wrapper around the clipboard API

37,211 16,304
@meforma/vue-copy-to-clipboard

Vue.js 3 plugin to copy text to clipboard

16,239 12
@mooth/copy

copy text to clipboard from native select element

0
nuxt-clipboard

A "copy to clipboard" module for Nuxt.js using vue-clipboard2

60,155 14

Version History

Version Released License
2.2.3 MIT
2.2.2
2.2.1
2.2.0
2.1.1
Pre-releases (2)
Version Released Vue License
3.0.0-next.1 ^3.2.45 MIT
3.0.0-next.0 ^3.2.45 MIT