• Stars
    star
    1,766
  • Rank 26,361 (Top 0.6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 8 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A simple vue2 binding to clipboard.js

vue-clipboard2

A simple vuejs 2 binding for clipboard.js

Install

npm install --save vue-clipboard2 or use dist/vue-clipboard.min.js without webpack

Usage

For vue-cli user:

import Vue from 'vue'
import VueClipboard from 'vue-clipboard2'

Vue.use(VueClipboard)

For standalone usage:

<script src="vue.min.js"></script>
<!-- must place this line after vue.js -->
<script src="dist/vue-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. See sample2, 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:

let container = this.$refs.container
this.$copyText("Text to copy", container)

Or you can let vue-clipboard2 set container to current element by doing this:

import Vue from 'vue'
import VueClipboard from 'vue-clipboard2'

VueClipboard.config.autoSetContainer = true // add this line
Vue.use(VueClipboard)

Sample

<div id="app"></div>

<template id="t">
  <div class="container">
    <input type="text" v-model="message">
    <button type="button"
      v-clipboard:copy="message"
      v-clipboard:success="onCopy"
      v-clipboard:error="onError">Copy!</button>
  </div>
</template>

<script>
new Vue({
  el: '#app',
  template: '#t',
  data: function () {
    return {
      message: 'Copy These Text'
    }
  },
  methods: {
    onCopy: function (e) {
      alert('You just copied: ' + e.text)
    },
    onError: function (e) {
      alert('Failed to copy texts')
    }
  }
})
</script>

Sample 2

<div id="app"></div>

  <template id="t">
    <div class="container">
    <input type="text" v-model="message">
    <button type="button" @click="doCopy">Copy!</button>
    </div>
  </template>

  <script>
  new Vue({
    el: '#app',
    template: '#t',
    data: function () {
      return {
        message: 'Copy These Text'
      }
    },
    methods: {
      doCopy: function () {
        this.$copyText(this.message).then(function (e) {
          alert('Copied')
          console.log(e)
        }, function (e) {
          alert('Can not copy')
          console.log(e)
        })
      }
    }
  })
  </script>

You can use your Vue instance vm.$el to get DOM elements via the usual traversal methods, e.g.:

this.$el.children[1].children[2].textContent

This will allow you to access the rendered content of your components, rather than the components themselves.

Contribution

PRs welcome, and issues as well! If you want any feature that we don't have currently, please fire an issue for a feature request.

License

MIT License

More Repositories

1

fresh-foods

ๆฏ้€ฑไธ€้ปžๅฐ็Ÿฅ่ญ˜
Python
104
star
2

windows-sucks

How to survive in Windows world (as a developer who loves unix)
PowerShell
87
star
3

ctf-writeup

My CTF write-up collection
C
64
star
4

twnhi-smartcard-agent

Alternative implement of Taiwan NHI smart-card agent
Python
51
star
5

sligen

Pitching like a boss
JavaScript
45
star
6

CTF-From-Zero-To-One

TDOH Conf 2016 ๆผ”่ฌ›็›ธ้—œ่ณ‡ๆ–™
Assembly
30
star
7

formatstring-exploit

Dead simple format string exploit payload generator
Python
25
star
8

idapython-cheatsheet

scripting IDA like a Pro
Python
22
star
9

zzvm

A tiny VM written in C, with assembler and disassembler
C
18
star
10

garena-authenticator

Garena Authenticator
JavaScript
17
star
11

MSDoggy

An old Taiwan MapleStory game hack.
C++
17
star
12

TWMS-Hacking-Data

Cheat Engine hacking script and pointer / structure data in history. I won't update these data but you can send PR and I'll accept
12
star
13

NewBeanfunLogin4TWMS

Start playing TWMS without browser.
C#
11
star
14

cli-tools

Inndy's commandline tools
Python
9
star
15

kses

HTML/XHTML filter written in PHP, forked from http://sourceforge.net/projects/kses/
PHP
8
star
16

gsheet-submission-review-tool

Google sheet submission review tool
HTML
8
star
17

scoreboard

A tiny ctf scoreboard
PHP
7
star
18

TerminalSummoner

Quick & dirty utilty to spawn Windows Terminal (Or powershell) with global hotkey
C#
7
star
19

windows-playground

How to use Windows API 101
C
6
star
20

dotfiles

Inndy's environment setting files
Shell
6
star
21

python-rsa

A pure python implementation of RSA algorithm
Python
6
star
22

hire-me

I had a job right now.
5
star
23

TDOH-l5g-challenges

Challenges at SITCON 2017
C
5
star
24

HackmeCTF

A simple CTF platform
JavaScript
5
star
25

vul-rpg

A damn vulnerable text-based role-playing-game
C
5
star
26

registration-time-chart

HTML
3
star
27

codiboard

List recently edited notes from your own CodiMD instance
Python
3
star
28

one4all

Grab some super power and start hacking regardless of operating system
C
3
star
29

super-simple-vulnerable-guestbook

Super Simple Vulnerable Guestbook
PHP
2
star
30

websec101

A set of vulnerable code for the security course in NTUST. (PHP only currently)
HTML
2
star
31

blog

HTML
2
star
32

SlideController

An simply slide controller for Linux
Python
2
star
33

ggpk-tools

C
2
star
34

python-terminal-emulator

Python
2
star
35

mingw_shellcode

C
2
star
36

ppapl

2
star
37

wolfrpgeditor-database-parser

Python
2
star
38

WCDESComp

A DES crypto component for C++ Builder / Dephi written in delphi.
Pascal
2
star
39

online-db

Collection of some cool online database
1
star
40

pytos

A Tower of Savior client implement in python. (Out of date)
Python
1
star
41

dmhy-torrent

A greasemonkey script for dmhy.org
JavaScript
1
star
42

PoE_Healer

Path of Exile Healer
Pascal
1
star
43

ais3-2017-final-ctf

CTF challenges I made for AIS3 2017 (https://ais3.org)
Python
1
star
44

eat-my-ram

Can you eat my RAM? >//////////<
C
1
star
45

LED-Matrix-Painter

LED-Matrix Painter
JavaScript
1
star
46

wtfbb.py

WTF.... BlackBoard CLI tool
Python
1
star
47

TDOHacker-SITCON-Summer-Camp-2014-Wargame

TDOHacker Wargame for SITCON Summer Camp 2014
C++
1
star
48

dll_export_list

Collection of dll export function list, in tsv format
Python
1
star