// 文件下载
export function downloadFile (url, data, method) {
let t = document.getElementById('ihr_table_export_form');
let curMethod = method || 'GET';
if (!t) {
t = document.createElement('form');
t.setAttribute('id', 'ihr_table_export_form');
t.setAttribute('style', 'display: none');
t.setAttribute('action', process.env.API_URL + url);
t.setAttribute('method', curMethod);
document.body.appendChild(t);
} else {
t.setAttribute('action', process.env.API_URL + url);
t.setAttribute('method', curMethod);
}
t.innerHTML = '';
var input = document.createElement('input');
input.setAttribute('name', 'lang');
input.setAttribute('value', getStore('lang') || 'en-US');
t.appendChild(input);
if (data) {
for (let key of Object.keys(data)) {
if (data[key] !== undefined && data[key] !== null) {
input = document.createElement('input');
input.setAttribute('name', key);
input.setAttribute('value', data[key]);
t.appendChild(input);
}
}
}
t.submit();
console.log('11111');
}
引入再调用import { downloadFile } from '@/utils/assist';
![](https://img.haomeiwen.com/i14803067/54a4291919271f82.png)
网友评论