拷贝文案
copyText(text = '') {
const input = document.createElement('input');
input.setAttribute('readonly', 'readonly');
input.setAttribute('value', text);
document.body.appendChild(input);
input.select();
input.setSelectionRange(0, 9999);
const copyResValue = document.execCommand('copy');
document.body.removeChild(input);
return copyResValue;
},
简单的数字格式划
.toLocaleString('en-US')
模拟用户调整浏览器
window.dispatchEvent(new Event('resize'))
返回随机字符串
function getRandomStr(len, prefix = '') {
let text = '', prefixLen = prefix ? prefix.length : 0;
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
for (let i = 0; i < len - prefixLen; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return prefix + text;
}