針對于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('下載失敗,請重試。')})},