结合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('只能选择一个文件')
      }
相关推荐
小李子呢02114 小时前
前端八股CSS(2)---动画的实现方式
前端·javascript
布局呆星6 小时前
Vue3 | 组件通信学习小结
前端·vue.js
竹林8189 小时前
RainbowKit 快速集成多链钱包连接:从“连不上”到丝滑切换的踩坑实录
前端·javascript
Ruihong9 小时前
你的 Vue 3 reactive(),VuReact 会编译成什么样的 React?
vue.js·面试
Ruihong9 小时前
你的 Vue 3 ref(),VuReact 会编译成什么样的 React?
vue.js·面试
一 乐9 小时前
酒店预订|基于springboot + vue酒店预订系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·论文·毕设·酒店预订系统
嗜好ya9 小时前
解决 Vite 项目中 import.meta.env 变量为 undefined 的问题
前端·javascript·vue.js
心连欣10 小时前
JS算法入门:图解“冒泡排序”,彻底搞懂双重循环的奥义
前端·javascript
浩星10 小时前
「Vue3 + Cesium 最佳实践」完整工程化方案
前端·javascript·vue.js