【导出Excel】Vue实现导出下载Excel文件(blob文件流)--亲测可用!


    // 下载blob文件流(暂不支持手机H5唤起下载文件!!!)

    downloadFile(res, name) {
        const blob = new Blob([res]); //axiosData.responseType = 'blob'; //这句话解决导出文件乱码问题
        const fileName = name + '.xls';
        // for IE
        if (window.navigator && window.navigator.msSaveOrOpenBlob) {
            window.navigator.msSaveOrOpenBlob(blob, fileName)
        } else {
            // for Non-IE (chrome, firefox etc.)
            const elink = document.createElement('a');
            elink.download = fileName;
            elink.style.display = 'none';
            elink.href = URL.createObjectURL(blob);
            document.body.appendChild(elink);
            elink.click();
            URL.revokeObjectURL(elink.href);
            document.body.removeChild(elink);
        }
    },

 

你可能感兴趣的:(舒工的Vue.js专栏)