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

阅读 135

2022-06-30

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’); 之间不能被异步过程隔开


精彩评论(0)

0 0 举报