zhangzengfei
2021-11-18 2f96ef3f59c0084d2943a7fdac9f47f51fe30da5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import Vue from "vue";
import Clipboard from "clipboard";
 
function clipboardSuccess() {
  Vue.prototype.$baseMessage("复制成功", "success");
}
 
function clipboardError() {
  Vue.prototype.$baseMessage("复制失败", "error");
}
 
export default function handleClipboard(text, event) {
  const clipboard = new Clipboard(event.target, {
    text: () => text,
  });
  clipboard.on("success", () => {
    clipboardSuccess();
    clipboard.destroy();
  });
  clipboard.on("error", () => {
    clipboardError();
    clipboard.destroy();
  });
  clipboard.onClick(event);
}