方法一:copy-to-clipboard
1.安装
npm i copy-to-clipboard
2.引入
import copy from "copy-to-clipboard"
3.使用
===>html
<div class="next" @click="copyFn">复制</div>
===>js
copyFn() {
copy("想要复制的内容");
},
方法二:clipboard
1.安装
npm i clipboard
2.引入
import Clipboard from "clipboard"
3.使用
===>html
<div class="next" data-clipboard-text="想要复制的内容">复制</div>
===>js
mounted() {
var clipboard = new Clipboard(".next");
clipboard.on("success", () => {
console.log("地址已复制");
});
clipboard.on("error", (e) => {
console.log("clipboard error", e)
});
},