The front end downloads excel files, etc., the project pure front end realizes file download

The simplest, with the address of the file, directly use the a tag to download (local download from the front end of the universal template):

  <a href="/user/test/xxxx.xls" download="文件名.xls">点击下载</a>

但是有个情况,比如txt,png,jpg等这些浏览器支持直接打开的文件是不会执行下载任务的,而是会直接打开文件,这个时候就需要给a标签添加一个属性“download”;

如果再vue项目中需要下载文件需要放在public文件夹下 需要下载的路径是相对于index.html文件路径 否则会提示下载文件未找到

注意:文件名称一定要用英文

If there is a problem that cannot be opened, first check your own path, and then see if the folder name is in English,这种方法绝对好用

一下文章还有更多的方法

https://blog.csdn.net/phhzhhh/article/details/106183647

https://blog.csdn.net/qq_35158525/article/details/103614391

https://www.cnblogs.com/xzybk/p/12696012.html

The above method is not compatible with IE browser

You can use this method:

<el-button size="mini" class="importBtn" v-if="downFlag" @click="download">下载模板</el-button>
download(){
    window.location='/perpon.xlsx'  // 在项目中的文件地址
},

 

Guess you like

Origin blog.csdn.net/qq_40055200/article/details/111408834