本质是 document.execCommand()
api 的使用, 见如下 demo:
function copy(str: string) {return new Promise(function(resolve, reject) {let success = falsefunction listener(e: any) {e.clipboardData.setData('text/plain', str)e.preventDefault()success = true}document.addEventListener('copy', listener)document.execCommand('copy')document.removeEventListener('copy', listener)success ? resolve() : reject()})}usage:copy(...).then(() => {})