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

@lxf2513/vue3-clipboard

v1.0.8

Published

clipboard for vue3

Downloads

116

Readme

vue3-clipboard

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

Install

npm install @lxf2513/vue3-clipboard or use <script type="module"> without npm

Usage

For vite user:

import { createApp } from 'vue'
import { VueClipboard } from '@lxf2513/vue3-clipboard'

const app = createApp({})

app.use(VueClipboard)

For standalone usage:

<html>
<head>
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.global.prod.min.js"></script>
</head>
<body>
  <button onclick="module.copy()">Copy</button>
  <script type="module">
  import { copyText } from 'https://cdn.jsdelivr.net/npm/@lxf2513/[email protected]/+esm'
  function copy() {
    copyText('https://github.com/luoxiangfan/vue3-clipboard', undefined, (statusTxt, evt) => {
      console.log(statusTxt) // 'success' or 'error'
      console.log(evt) // Clipboard Event
    })
  }
  module.copy = copy
  </script>
  <script>
    const module = {}
  </script>
</body>
</html>

I want to copy texts without a specific button!

container option is available like this:

In Options API:

const container = this.$refs.container
this.$copyText((text: 'https://github.com/luoxiangfan/vue3-clipboard'), container)

In Composition API:

import { copyText } from '@lxf2513/vue3-clipboard'
import { ref } from 'vue'

const container = ref(null)
copyText('https://github.com/luoxiangfan/vue3-clipboard', container.value)

Or you can let @lxf2513/vue3-clipboard set container to current element by doing this:

import { createApp } from 'vue'
import { VueClipboard } from '@lxf2513/vue3-clipboard'

const app = createApp({})

app.use(VueClipboard, {
  autoSetContainer: true,
  appendToBody: true,
})

Sample 1

<template>
  <div class="container">
    <button
      v-clipboard:copy="message"
      v-clipboard:success="handleSuccess"
      v-clipboard:error="handleError"
    >
      Copy
    </button>
  </div>
</template>

<script setup>
  const message = 'https://github.com/luoxiangfan/vue3-clipboard'
  const handleSuccess = (e) => {
    alert('Copied text: ' + e.text)
  }
  const handleError = (e) => {
    alert('Copy failed')
  }
</script>

Sample 2

<template>
  <div class="container">
    <button
      @click="$copyText('https://github.com/luoxiangfan/vue3-clipboard')"
    >
      Copy
    </button>
  </div>
</template>

Sample 3

<template>
  <div class="container">
    <button type="button" @click="copy">Copy</button>
  </div>
</template>

<script setup>
  import { copyText } from '@lxf2513/vue3-clipboard'

  const copy = () => {
    copyText('https://github.com/luoxiangfan/vue3-clipboard', undefined, (statusTxt, evt) => {
      console.log(statusTxt) // 'success' or 'error'
      console.log(evt) // Clipboard Event
    })
  }
</script>