vue clipboard 复制到粘贴板功能
import Clipboard from 'clipboard';
//复制到粘贴板
function handleClipboard(text: string, event: MouseEvent) {
const clipboard = new Clipboard(event.target as Element, {
text: () => text,
});
clipboard.on('success', () => {
this.$message.success('复制成功');
clipboard.destroy();
});
clipboard.on('error', () => {
this.$message.error('复制失败');
clipboard.destroy();
});
(clipboard as any).onClick(event);
}
使用
<el-button type="text" @click="handleClipboard('我是被复制内容', $event)">复制</el-button>
还没有评论,来说两句吧...