需求
接口报错时,给出错误提示,并给用户提供一键复制错误参数的功能
实现
“使用textarea支持换行,使用input不支持换行”
====》使用textarea 会保留原始信息的格式,否则,复制到的数据没有格式
// 提供一键复制content的功能
export function copy(content) {
const text = document.createElement('textarea');
text.value = content;
document.body.appendChild(text);
text.select(); // 选择对象
if (document.execCommand('copy')) {
document.execCommand('copy');
}
// 执行浏览器复制命令
document.body.removeChild(text);
}