Skip to content
项目

关于

适用于 Vue.js 2 和 3 的简洁强大剪贴板插件

网站与应用开发

这些数字如何统计

实测星标增长

24小时
0
7天
0
15天
-1
1个月
正在收集历史

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README.md

原文

npm npm

Supporters

Check them out.

Install

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

Vue.use(Clipboard)

Usage

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'

await 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)
    }
  }
}

How it works

copy / $clipboard is an async call. Firstly, library makes an attempt to update clibpoard using execCommand, if that operation is unsuccessful it makes an attemnt to use Navigator Clipboard API and automatically requests access, waits for access to be granted, then writes to clipboard.

Demo

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

Compatibility

探索相关项目

加载中…