document.execCommand('copy')踩的坑

let input = document.createElement('input');
document.body.appendChild(input);
input.setAttribute('value', JSON.stringify(this.cachePrintList));
input.select();
let result = document.execCommand('copy');

复制元素内容代码,此方法在axios或者异步中无法使用,复制会失败,浏览器出于安全考虑,只能在用户操作中,同步才能复制

posted @ 2024-12-18 17:53  洋三岁  阅读(74)  评论(0)    收藏  举报
友情链接: 梦想农夫