<el-button size="small" type="success" @click="download()">下載模板</el-button>
download() {
let params = {
tempType: 'traffic_police'
}
this.http({
method: 'get',
responseType: 'blob', //防止返回亂碼
// url: '/static/fileExcel/buy.xlsx',//正式
url: this.baseUrl3 + '/menuPermission/downloadExcel',
params: params
}).then(res => {
if (res.status == '200') {
// downloadFile (data, name)
let data = res.data;
if (!data) {
this.$message.error('下載失敗,解析數據為空!')
return
}
// const datetime = Date.now();
// 創建一個新的url,此url指向新建的Blob對象
let url = window.URL.createObjectURL(new Blob([data]))
// 創建a標簽,並隱藏改a標簽
let link = document.createElement('a')
link.style.display = 'none'
// a標簽的href屬性指定下載鏈接
link.href = url
//setAttribute() 方法添加指定的屬性,並為其賦指定的值。
let fileName = '接口模板.xlsx'
link.setAttribute('download', fileName)
document.body.appendChild(link)
link.click()
// this.$message.success('導出成功');
this.modal3 = false;
} else {
this.$message.error('導出失敗,請嘗試重新導出');
}
});
},