常用函数
debounce(fn, delay=500) {
debounce(fn, delay=500) {
let timer;
return function() {
const that = this;
const args = arguments;
if(timer) {
clearTimeout(timer);
}
timer = setTimeout(() => {
timer = null;
fn.apply(that, args);
}, delay)
}
}
防抖函数
[...new Set(array)]
数组去重
[...new Set('ababc')].join('')
字符串去重
downFileUrl(parameter) {
if (typeof window.navigator.msSaveOrOpenBlob !== 'undefined') {
window.navigator.msSaveBlob(new Blob([data]), fileName);
} else {
const url = window.URL.createObjectURL(new Blob([parameter.data])); const link = document.createElement('a');
link.style.display = 'none'; link.href = url; link.setAttribute('download', parameter.name); // 替换为你想要保存的文件名.xlsx document.body.appendChild(link); link.click(); // 下载完成后移除 <a> 标签和 URL 对象 document.body.removeChild(link); window.URL.revokeObjectURL(url);
} }
文件下载,用于后端返回文件时接收的数据处理
Upload(parameter) { const form = new FormData(); form.append('file', parameter); return axios({ url: url, method: 'post', data: form, headers: { 'Content-Type': 'multipart/form-data' }, timeout: 300000, }); }
文件上传,设置上传超时时间
浙公网安备 33010602011771号