vue clipboard 复制到粘贴板功能

太过爱你忘了你带给我的痛 2023-02-25 16:19 397阅读 0赞
  1. import Clipboard from 'clipboard';
  2. //复制到粘贴板
  3. function handleClipboard(text: string, event: MouseEvent) {
  4. const clipboard = new Clipboard(event.target as Element, {
  5. text: () => text,
  6. });
  7. clipboard.on('success', () => {
  8. this.$message.success('复制成功');
  9. clipboard.destroy();
  10. });
  11. clipboard.on('error', () => {
  12. this.$message.error('复制失败');
  13. clipboard.destroy();
  14. });
  15. (clipboard as any).onClick(event);
  16. }

使用

  1. <el-button type="text" @click="handleClipboard('我是被复制内容', $event)">复制</el-button>

发表评论

表情:
评论列表 (有 0 条评论,397人围观)

还没有评论,来说两句吧...

相关阅读