复制到黏贴板
安装
$ yarn add copy-to-clipboard
1
使用
import copy from "copy-to-clipboard";
copy("Text");
// Copy with options
copy("Text", {
debug: true,
message: "Press #{key} to copy"
});
// 判断是否复制成功
const isCopySuccess = copy("Text");
if (isCopySuccess) {
message.success("复制成功!");
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
简易封装
import copy from "copy-to-clipboard";
import { message } from "antd";
const copyToClipboard = (text, options) => {
const isCopySuccess = copy(text, options);
if (isCopySuccess) {
message.success(options.successMsg || "复制成功!");
} else {
message.error(options.failMsg || "复制失败!");
}
};
export default copyToClipboard;
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13