文件放在public
方案一:
<a-button
type="primary"
@click="downloadMeaTemp"
>
模板下载
</a-button>
download () {
axios.get('/template.xlsx', {
//静态资源文件夹public
responseType: 'blob',
}).then(response => {
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
let fname = '模板.xlsx';
link.href = url;
link.setAttribute('download', fname);
document.body.appendChild(link);
link.click();
}).catch(error => {
console.log('error:' + JSON.stringify(error))
});
},
方案二:
<a
href="/template.xlsx"
download="模板.xlsx"
style="marginleft: 10px"
>
<a-button type="primary" style="margin-right: 15px">
模板下载
</a-button>
</a>