逻辑简单,直接上代码
var xhr = new XMLHttpRequest()
xhr.open('get', '${ctx!}/admin/v1/licence/' + id)
xhr.responseType = "blob" // 设置响应数据类型为blob, 不设置会出现下载的文件比源文件更大
xhr.send()
xhr.onload = function() {
var blob = new Blob([this.response], { type: this.responseType }); // ArrayBuffer , mime类型
// console.log(this.response.length, blob.size)
var a = document.createElement('a');
var url = window.URL.createObjectURL(blob);
a.href = url;
a.download = 'license.lic';
a.click();
}