<el-button
type=""
circle
size="mini"
icon="el-icon-share"
id="copyBtn"
@click="shareTaskDetail"
></el-button>
import ClipboardJS from "clipboard";
// npm install --save clipboard
/**
* @description: 点击分享任务详情,自动复制链接
* @return {*}
*/
async shareTaskDetail() {
console.log("this.copyUrl", this.copyUrl);
// 复制链接
const clipboard = new ClipboardJS("#copyBtn", {
text: (trigger) => {
const codeStr = this.copyUrl;
this.$message.success("分享链接已复制到剪切板");
return codeStr;
},
});
clipboard.on("error", (e) => {
this.$message.error("复制失败");
});
// return;
setTimeout(() => {
// 销毁
clipboard.destroy();
}, 2000);
},