前后端分离,前端通过ng的$http传post到后端,后端返回responsetype为application/vns.ms-excel的数据,请问有什么方式才能让浏览器下载excel文件呢?
// 创建a标签模拟下载 function exportExcel(params, filename) { return $http({ url: '/api/exportExcel', method: "POST", headers: { 'Content-type': 'application/json' }, params: params, responseType: 'arraybuffer' }).success(function (data) { var blob = new Blob([data], {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}); var objectUrl = URL.createObjectURL(blob); var a = document.createElement('a'); document.body.appendChild(a); a.setAttribute('style', 'display:none'); a.setAttribute('href', objectUrl); a.setAttribute('download', filename); a.click(); URL.revokeObjectURL(objectUrl); }); }