Vue项目里面用a标签下载本地文件

1. 直接将 href 设置为相对路径,这种方法在对于非Vue项目是没有问题的

<a href="./Template.xlsx">download</a>

2. 但是在vue项目里面会报错

 

  解决办法:将文件放在static文件夹下,再用a标签或者js下载

<a href="/static/Template.xlsx" download>download</a>
  downloadTemp() {
    window.location.href = '/static/Template.xlsx';
  }

此时就可以正常下载了

 

posted @ 2022-05-24 15:36  小情绪^_^  阅读(2743)  评论(0)    收藏  举报