document.execCommand(‘copy’);//实现剪切复制剪切版的主要实现
虽然目前暂时不推荐使用,但是目前也只有这个实现,便还是继续使用
链接:https://developer.mozilla.org/zh-CN/docs/Web/API/Document/execCommand
const copyUrl = (url) => {
const input = document.createElement('input');
document.body.appendChild(input);
input.setAttribute('value', url);
input.select();
if (document.execCommand('copy')) {
document.execCommand('copy');
console.log('复制成功')
}
document.body.removeChild(input);
};