vue中 element 实现点击复制粘贴功能

 copyUrl(data){
    
    
        let url = data;
        let oInput = document.createElement('input');
        oInput.value = url;
        document.body.appendChild(oInput);
        oInput.select(); // 选择对象;
        console.log(oInput.value)
        document.execCommand("Copy"); // 执行浏览器复制命令
        this.$message({
    
    
          message: '已成功复制到剪切板',
          type: 'success'
        });
        oInput.remove()
      },
<el-button type="primary" plain @click="copyUrl(link2)">复制链接</el-button>

用户触发的事件和 document.execCommand(‘copy’); 之间不能被异步过程隔开

前端面试题大全(1000+)扫码查看

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_42981560/article/details/110118927
今日推荐