@soerenmartius/vue3-clipboard

A Vue 3 binding for clipboard.js
323,493 104
Install
npm install @soerenmartius/vue3-clipboard
Latest Version:0.1.2
Vue:3
License:MIT
Last Updated:Oct 28, 2023
Links: GitHub  ·  npm
Maintainer: soerenmartius

vue3-clipboard

Build

Clipboard.js bindings for Vue 3.

This repository is a port of Inndy's vue-clipboard2 plugin for Vue3.

Install

npm install --save @soerenmartius/vue3-clipboard

Usage

Import the v-clipboard directive globally

src/main.ts

import { createApp } from 'vue'
import App from './App.vue'
import { VueClipboard } from '@soerenmartius/vue3-clipboard'

createApp(App).use(VueClipboard).mount('#app')

Import the v-clipboard directive for a specific component

Examples

Apply the v-clipboard directive to an element

<template>
  <input v-model="value" />
  <button v-clipboard="value">Copy</button>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue'

export default defineComponent({
  setup() {
    const value = ref('lorem')

    return { value }
  },
})
</script>

Copy value of an input, and handle events separately.

<template>
  <input v-model="value" />
  <button
    v-clipboard:copy="value"
    v-clipboard:success="onSuccess"
    v-clipboard:error="onError"
  >
    Copy
  </button>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue'

export default defineComponent({
  setup() {
    const value = ref('lorem')

    const onSuccess = () => {
      console.log('success')
    }

    const onError = () => {
      console.log('error')
    }

    return { value, onSuccess, onError }
  },
})
</script>

Standalone usage of the toClipboard function

<template>
  <input v-model="value" />
  <button @click="toClipboard(value)">Copy</button>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue'

import { toClipboard } from '@soerenmartius/vue3-clipboard'

export default defineComponent({
  setup() {
    const value = ref('lorem')

    return { value, toClipboard }
  },
})
</script>

Contributing

Contributions are always encouraged and welcome! For the process of accepting changes, we use Pull Requests. For feature requests please fill an issue.

License

License: MIT

Related Packages

vue-clipboard2

A Vuejs2 & Vuejs3 binding for clipboard.js

5,074,076 1,750
vue3-clipboard

A Vuejs3 binding for clipboard.js

895,108 24
vue-clipboard3

Easily copy to clipboard with Vue 3

2,441,248 143
@enso-ui/clipboard

Simple vue clipboard copy

8,639 1
@liberu-ui/clipboard

Simple vue clipboard copy

583 0

Version History

Version Released License
0.1.2 MIT
0.1.1 MIT
0.1.0 MIT
0.0.9 MIT
0.0.8 MIT