针对于Ant Design 框架
1.在你的api文件下编写接口路径
import request from '@/utils/request'
import storage from 'store'import {AUTHORIZATION} from '@/store/mutation-types'
const api = {downloadVocabularyTemplate:'/vocabulary/downloadVocabularyTemplate',
}export function downloadVocabularyTemplate() {return request({url: api.downloadVocabularyTemplate,method: 'GET',responseType: 'blob',})
}
2.编写按钮点击事件
xaizai () {downloadVocabularyTemplate().then(response => {console.log(response)const blob = new Blob([response], { type: 'application/vnd.ms-excel' })saveAs(blob, '下载文件名称.xls')}).catch(error => {console.error('Download failed:', error)this.$message.error('下载失败,请重试。')})},