功能效果

- 这里用txt文件举例说明别的类型的文件也是支持的csv,excel,img都可以

代码具体实现
<template>
<a href="javascript:void(0);" @click="download()">
<el-button type="primary">下载<i class="el-icon-download el-icon--right"></i></el-button>
</a>
</template>
methods:{
download(){
return this.downloadFile("dengue.txt")
},
downloadFile(params){
axios.get(`file/${params}`, {
responseType: 'blob',
}).then(response => {
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
let fname = params;
link.href = url;
link.setAttribute('download', fname);
document.body.appendChild(link);
link.click();
}).catch(error => {
console.log('error:'+JSON.stringify(error))
});
}
},