code:
const copyText = (text) => {
var input = document.createElement('textarea');
document.body.appendChild(input);
input.value = text; // 修改文本框的内容
input.select(); // 选中文本
document.execCommand("copy"); // 执行浏览器复制命令
document.body.removeChild(input);
return '复制成功';
}
export default copyText;
兼容性:
tips
如果还不清楚或者想交个朋友的同学可以微信联系我:qq981145483(备注:csdn fe)