0
点赞
收藏
分享

微信扫一扫

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

你的益达233 2022-06-30 阅读 133
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 条评论