结合element和原生写法<a>标签实现excel文件的下载和上传

本项目要求:用户下载excel模板,填写资料后上传

模板保存在项目文件中,使用a标签点击下载

html

html 复制代码
         <el-upload
                  v-model:file-list="fileList"
                  :before-upload="beforeUpload"
                  :limit="1"
                  :on-exceed="handleExceed"
                  :show-file-list="false"
                >
                  <el-button size="small" type="primary">
                    <vab-icon icon="file-excel-2-line" />
                    导入EXCEL
                  </el-button>
                </el-upload>
                
                <el-button size="small" type="primary">
                  <vab-icon icon="download-2-line" />
                  <a
                    download="收款导入模板"
                    href="./static/collection.xls"
                    style="color: #ffffff"
                  >
                    下载模板
                  </a>
                </el-button>

上传功能:

javascript 复制代码
export function importExcelDetail(file) {
  return request({
    url: '/api/v1/pri/cost-master/import-excel-detail',
    method: 'post',
    data: {
      files: [file],
    },
  })
}
javascript 复制代码
      const beforeUpload = (file) => {
        importExcelDetail(file).then((res) => {
          if (res.code === 200) {
            $baseMessage('导入成功!', 'success')
            fetchData()
          }
        })
      }

      const handleExceed = () => {
        ElMessage.warning('只能选择一个文件')
      }
相关推荐
默_笙3 小时前
🏛 给 AI 配一间办公室:Harness Engineering 六大模块与它的实现
前端·javascript
linux_cfan4 小时前
videojs v10 源代码系列解读:14 · 谓词守卫:在运行时安全地调用能力
前端·javascript·音视频
+VX:Fegn08955 小时前
计算机毕业设计|基于springboot + vue旅游管理系统(源码+数据库+文档)
java·开发语言·vue.js·spring boot·课程设计
雪芽蓝域zzs6 小时前
第 7 章:双 Y 轴组合图(柱状 + 折线,看板高频场景)
vue.js·echars
一 乐6 小时前
二手交易平台|基于springboot + vue二手交易平台(源码+数据库+文档)
java·数据库·vue.js·spring boot·小程序
天若有情6736 小时前
【纯前端小工具】公历生日转农历,批量查询每年农历生日对应的公历日期(GitHub Pages在线直接用)
前端·javascript·github pages·农历转换·lunisolar·网页小工具
vx-程序开发7 小时前
【计算机毕设】django校园跑腿服务系统83141
java·数据库·vue.js·spring boot·spring·elasticsearch·django
林语琛7 小时前
我写的 switch…break 被 Babel 偷偷吞了
前端·javascript·babel
liuchangng7 小时前
Jev 模型研究:从生成式大模型到决策式模型——System One、RLCD 校准与采用边界
java·javascript·人工智能·python·深度学习
一 乐7 小时前
养老院管理系统|基于springboot + vue养老院管理系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·毕业设计