使用clipboard这个方法复制需要点击两次才能复制成功,然后第一次点击是数据库是产生数据的但是未复制成功,第二次点击复制出来的数据是第一次的数据,能请教一下这种情况应该如何解决
function copy(copyText) {
navigator.clipboard
.writeText(copyText)
.then(() => {
console.log('复制成功')
})
.catch(() => {
const input = document.createElement('input');
document.body.appendChild(input);
input.setAttribute('value', copyText);
input.select();
if (document.execCommand('copy')) {
document.execCommand('copy')
}
document.body.removeChild(input);
console.log('复制成功')
})
}