npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue3-clipboard

v1.0.0

Published

A Vuejs3 binding for clipboard.js

Downloads

73,741

Readme

vue3-clipboard

A simple vuejs 3 binding for clipboard.js, based on Inndy/vue-clipboard2

Install

npm install --save vue3-clipboard or use dist/vue3-clipboard.min.js without npm

Usage

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>

I want to copy texts without a specific button!

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.

It doesn't work with bootstrap modals

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

Sample

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

Sample 2

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