```java
export function questionnaireExport(params) {
return request({
url: 'guankeQuestionnaire/questionnaire/export',
method: 'GET',
responseType: 'blob',
params
})
}
* 统计图表
* @param {Object} params
* @param {Number} params.imgId
*/
export function download(params) {
return request({
url: 'guankeQuestionnaire/questionnaire/setting/image/download',
method: 'GET',
responseType: 'blob',
params
})
}
imgDlown() {
console.log(this.dataList.setting.backgroundImgId)
download({ imgId: this.dataList.setting.backgroundImgId }).then(res => {
const filename = res.headers['content-disposition']
const blob = new Blob([res.data])
var downloadElement = document.createElement('a')
var href = window.URL.createObjectURL(blob)
downloadElement.href = href
downloadElement.download = decodeURIComponent(
filename.split('filename=')[1]
)
document.body.appendChild(downloadElement)
downloadElement.click()
document.body.removeChild(downloadElement)
window.URL.revokeObjectURL(href)
}).catch((err) => {
console.log(err)
})
}
questionnaireExport() {
questionnaireExport({ questionnaireId: this.$route.params.id }).then(
res => {
const filename = res.headers['content-disposition']
const blob = new Blob([res.data])
var downloadElement = document.createElement('a')
var href = window.URL.createObjectURL(blob)
downloadElement.href = href
downloadElement.download = decodeURIComponent(
filename.split('filename=')[1]
)
document.body.appendChild(downloadElement)
downloadElement.click()
document.body.removeChild(downloadElement)
window.URL.revokeObjectURL(href)
}
)
},`在这里插入代码片`
下载附件
downZip() {
console.log(this.dowloadData);
downZip(this.dowloadData).then((res) => {
const blob = new Blob([res.data], { type: "application/zip" });
if ("download" in document.createElement("a")) {
// 支持a标签download的浏览器
const link = document.createElement("a"); // 创建a标签
console.log(res.headers);
link.style.display = "none";
link.href = URL.createObjectURL(blob);
document.body.appendChild(link);
link.click(); // 执行下载
URL.revokeObjectURL(link.href); // 释放url
document.body.removeChild(link); // 释放标签
} else {
// 其他浏览器
navigator.msSaveBlob(blob);
}
loading.close();
});
},