Use of clipboard in vue

Source: Internet
Author: User
Introduction

Used on the pageclipboardYou can copy and paste it,clipboardCan directly write content to the clipboard

Install
npm install --save clipboard
Method 1
& Lt; Template & gt; & lt; span & gt ;{{ code }}& lt;/span & gt; & lt; I class = "El-icon-document" Title = "click to copy" @ click = "copyactivecode ($ event, code)"/& gt; & lt;/template & gt; // methodscopyactivecode (E, text) {const clipboard = new clipboard(e.tar get, {text: () = & gt; text}) clipboard. on ('success', E = & gt; {This. $ message ({type: 'success', message: 'copied successfully'}) // release the memory clipboard. off ('error') clipboard. off ('success') clipboard. destroy ()}) clipboard. on ('error', E = & gt; {// copying this. $ message ({type: 'waning', message: 'This browser does not support automatic copying'}) // release the memory clipboard. off ('error') clipboard. off ('success') clipboard. destroy ()}) clipboard. onclick (e )}
Method 2
& Lt; Template & gt; & lt; span & gt ;{{ code }}& lt;/span & gt; & lt; I id = "tag-Copy" & lt; -- use the class as the selector identifier -- & gt;: Data-clipboard-TEXT = "code" & lt; -- content to be copied -- & gt; Class = "El-icon-document" Title = "click to copy" @ click = "copyactivecode ($ event, code) "/& gt; & lt;/template & gt; // methodscopyactivecode () {const clipboard = new clipboard (" # tag-Copy ") clipboard. on ('success', E = & gt; {This. $ message ({type: 'success', message: 'copied successfully'}) // release the memory clipboard. destroy ()}) clipboard. on ('error', E = & gt; {// copying this. $ message ({type: 'waning', message: 'This browser does not support automatic copying'}) // release the memory clipboard. destroy ()})}

Original article address: 1190000016726633

Use of clipboard in vue

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.