对于 execCommand 来复制的使用应该不会很陌生,这几天使用的碰上了一个新问题,此方法在请求的时候是无法使用的,往下看👇

默认使用复制

const copy = value => {
let inp = document.createElement('input');
inp.setAttribute('value', value)
document.body.appendChild(inp);
inp.select();
document.execCommand('copy')
document.body.removeChild(inp)
}

在正常情况下 document.execCommand('copy') 是返回 true 的,但是在有异步请求的情况下会返回 false;

const copy = value => {
let inp = document.createElement('input');
inp.setAttribute('value', value)
document.body.appendChild(inp);
inp.select();
+ if (document.execCommand('copy')) {
document.execCommand('copy')
+ }
document.body.removeChild(inp)
}