安装 js-file-download
npm install js-file-download --save
使用
import axios from 'axios';
loadFile (row) {
let p = {downLoadAddr: row.filePath, oldFileName: row.fileName};
let url = apiBase.slice(0, apiBase.indexOf('/api/'));
axios({
method: 'get',
url: `${url}/ym/file/download`,
params: {...p},
headers: {
'Content-type': 'application/x-www-form-urlencoded'
},
responseType: 'arraybuffer'
}).then((response) => {
this.download(response.data, row.fileName);
});
},
download (data, fileName) {
let fileDownload = require('js-file-download');
fileDownload(data, fileName, 'application/vnd.ms-excel');
}