使用navigator.clipboard.writeText(value);相比以前更加简洁,采用promise实现
//旧:
let oInput = document.createElement('input');
oInput.value = value;
document.body.appendChild(oInput);
oInput.select(); // 选择对象;
document.execCommand("Copy"); // 执行浏览器复制命令
this.$Message.success('复制成功');
oInput.remove()
//新:
navigator.clipboard.writeText(value).then(() => {
this.$Message.success('复制成功');
});
网友评论