<template>
<el-button type="primary" size="large" @click="fileDownload">下载模版文件(Excel文件)</el-button>
</template>
<script lang="ts">
import { Component, Vue } from 'vue-property-decorator';
import axios from 'axios';
import download from 'downloadjs';
@Component({
name: 'FileDownload'
})
export default class extends Vue {
//下载模版文件
private fileDownload() {
axios.get('http://www.lihefei.com/download', {
params: {
id: 123456
},
responseType: 'blob' //设置响应数据类型为blob
}).then(
(resolve: any) => {
let blob = resolve.data; //文件数据流
let fileName = 'template.xls'; //文件名,
let mimeType = 'application/vnd.ms-excel'; //xls格式文件对应的类型为:application/vnd.ms-excel
download(blob, fileName, mimeType); //下载文件
}
);
}
</script>
Vue+Elementui+Axios+TypeScript+downloadjs下载文件
最新推荐文章于 2024-02-29 23:31:36 发布