JS realizes the copy function Compatible with IOS, IOS realizes the copy function through JS

The conventional copy method is always false because **document.execCommand()** is not executed in the IOS system and cannot be copied.
The solution is implemented using clipboardjs

manual

Install the plugin (it is recommended to use yarn to install)

npm install clipboard --save

import plugin

import ClipboardJS from "clipboard";

use

Note: After instantiating ClipboardJS in the mounted phase , the DOM you passed in (parameter 1) will be clicked and monitored to trigger copy; data-clipboard-text is copied to the text content;
in the triggered DOM node If you add an additional click event, you are not sure whether it will conflict with this method, but you can do corresponding event processing in its success callback. There are more than one of the following
methods to use. It can also be configured by other methods such as passing parameters. If you want to use other solutions that are more suitable for you, please refer to the documentation.

Guess you like

Origin blog.csdn.net/lys20000913/article/details/130932945
Recommended