Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
vue3-clipboard
Advanced tools
Readme
A simple vuejs 3 binding for clipboard.js, based on Inndy/vue-clipboard2
npm install --save vue3-clipboard
or use dist/vue3-clipboard.min.js
without npm
For vue-cli user:
import { createApp } from 'vue'
import VueClipboard from 'vue3-clipboard'
const app = createApp({})
app.use(VueClipboard)
For standalone usage:
<script src="vue.min.js"></script>
<!-- must place this line after vue.js -->
<script src="dist/vue3-clipboard.min.js"></script>
Yes, you can do it by using our new method: this.$copyText
,
where we replace the clipboard directives with a v-on directive.
Modern browsers have some limitations like that you can't use window.open
without a user interaction.
So there's the same restriction on copying things! Test it before you use it. Make sure you are not
using this method inside any async method.
Before using this feature, read: this issue and this page first.
See clipboardjs document and this pull request, container
option is available like this:
In Options API:
const container = this.$refs.container
this.$copyText((text: 'Text to copy'), container)
In Composition API:
import { copyText } from 'vue3-clipboard'
import { ref } from 'vue'
const container = ref(null)
copyText('Text to copy', container.value)
Or you can let vue3-clipboard
set container
to current element by doing this:
import { createApp } from 'vue'
import VueClipboard from 'vue3-clipboard'
const app = createApp({})
app.use(VueClipboard, {
autoSetContainer: true,
appendToBody: true,
})
<template>
<div class="container">
<button type="button" v-clipboard:copy="message" v-clipboard:success="onCopy" v-clipboard:error="onError">
Copy!
</button>
</div>
</template>
<script>
export default {
setup() {
const message = 'Hello Clipborad!'
const onCopy = (e) => {
alert('You just copied: ' + e.text)
}
const onError = (e) => {
alert('Failed to copy texts')
}
return { message, onCopy, onError }
},
}
</script>
<template>
<div class="container">
<button type="button" @click="doCopy">Copy!</button>
</div>
</template>
<script>
import { copyText } from 'vue3-clipboard'
export default {
setup() {
const doCopy = () => {
copyText('Hello Clipborad', undefined, (error, event) => {
if (error) {
alert('Can not copy')
console.log(error)
} else {
alert('Copied')
console.log(event)
}
})
}
return { doCopy }
},
}
</script>
FAQs
A Vuejs3 binding for clipboard.js
The npm package vue3-clipboard receives a total of 10,145 weekly downloads. As such, vue3-clipboard popularity was classified as popular.
We found that vue3-clipboard demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.