Home  >  Article  >  Web Front-end  >  Vue quickly copies content to the pasteboard (code attached)

Vue quickly copies content to the pasteboard (code attached)

php中世界最好的语言
php中世界最好的语言Original
2018-05-10 14:27:194491browse

This time I will bring you Vue to quickly copy content to the pasteboard (with code). What are the precautions for Vue to quickly copy content to the pasteboard? The following is a practical case, let's take a look.

1 . npm installed into the project directory file

npm install clipboard --save

2 . import the introduction file

import Clipboard from 'clipboard';

3 . Write the content to be copied in the data-clipboard-text of the custom attribute in the required html element

<button class="copyBtn" :data-clipboard-text = "https://www.baidu.com/" type="text">复制地址</button>

4. Find the content in an element by class name in JavaScript.

let clipboard = new Clipboard('.copyBtn');

That’s it. If you need this address, just

reference the clipboard variable in the method. If not, Don't worry about this variable, it doesn't need any processing. After clicking the button with the class name copyBtn, just Ctrl v.

I believe you have mastered the method after reading the case in this article, more Please pay attention to other related articles on the php Chinese website!

Recommended reading:

aggregate cascade query implementation steps

JS analysis of the method of generating a QR code image from a link

The above is the detailed content of Vue quickly copies content to the pasteboard (code attached). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn