1.安装npm包
npm i clipboard
2.封装tools方法
import Clipboard from 'clipboard';
/**
* 复制
* @param className 类名
* @param copyName 复制字段
* @param callback 成功回调
*/
export const copyContentHandle = (className: any, copyName: any, successCallBack?: any) => {
let clipboard = new Clipboard(className, {
text: function () {
return copyName;
}
});
clipboard.on('success', (e) => {
message.success('复制成功!');
if (successCallBack) {
successCallBack();
}
// 释放内存
clipboard.destroy();
});
clipboard.on('error', (e) => {
message.error('复制失败!');
clipboard.destroy();
});
};
3.如何使用
<a-button
type="link"
@click="runRecordCopyHandle(record)"
class="tag"
style="padding: 0"
>
复制
</a-button>
const runRecordCopyHandle = (e: any) => {
copyContentHandle('.tag', e?.sqlContent);
},
标签:功能,successCallBack,copyName,param,clipboard,复制,any
From: https://www.cnblogs.com/songkomei/p/17972177