vue,react,angular ,Jq. 都支持。 原生JS 下载任何文件?

利用from 表单提交,直接模拟CSS from 表达去下载文件

/*
url: 下载地址
method:get || post 表单提交方式
param: 携带参数
*/ 
export const downLoad = (url,method,param) => {
    const form = document.createElement('form');
    form.style.display = 'none';
    form.method = method || 'get';
    form.action = url;
    const download_form = document.createElement('div');
    download_form.style.display = 'none';
    document.body.appendChild(download_form);
    const frage = document.createDocumentFragment();  // 收集文档碎片
    for (const key in param) {
        if(param.hasOwnProperty(key)) {
            const input = document.createElement('input');
            input.type = 'hidden';
            input.name = key;
            input.value = param[key];
            frage.appendChild(input);
        }
    }
    form.appendChild(frage);
    download_form.appendChild(form);
    form.submit();

    document.body.removeChild(download_form);

}

  就可以直接下载任何文件了, 不需要关注自己使用的ajax 还是axios 还是JQ,以默认原生方式提交