Vue下载excel文件模板

注意:

1.模板一定是英文名

2.使用相对于index.html的路径

3.a标签同理

<a href="./static/template.xlsx" download="模板.xlsx"></a>

第一步:

 vue2.0版本的在项目根目录下的static文件夹,放入“文件模板.xlsx”文件。

 vue3.0版本的在项目public目录下新建static文件夹,放入“文件模板.xlsx”文件。

第二步:

  在按钮中加入事件

  <el-button icon="el-icon-download" size="medium" @click="downloadTemplate">模板下载</el-button>

第三步:

在 methods中写入如下方法:

downloadTemplate() {
            let a = document.createElement('a')
            a.href = './static/template.xlsx'
            a.download = '文件模板.xlsx'
            a.style.display = 'none'
            document.body.appendChild(a)
            a.click()
            a.remove()
        },

 

posted @ 2022-09-27 11:42  往暮  阅读(1223)  评论(0)    收藏  举报