0
点赞
收藏
分享

微信扫一扫

vue简单的文件上传及下载

DYBOY 2022-03-18 阅读 70

1.上传代码

 <el-upload :action="'/xxx'" :on-success="handleSuccess" :on-change="handleChangePic" accept=".xls,.xlsx">
        <el-button size="small" type="primary">上传资料</el-button>
 </el-upload>

 methods: {
    handleSuccess(res, file) {
      // action 上传时的回调
      this.ifload = false;
      if (res.code === 200) {
        this.$message.success('文件导入成功');
        this.fileList = [];
        this.handleClose();
      } else {
        this.$message.error(res.msg || '文件导入失败,稍后重试');
      }
    }
}

2.下载代码

<el-button type="primary" size="small" @click="download">下载模板</el-button>

methods: {
     download() {
      const a = document.createElement('a');
      a.target = '_blank';
      a.href = `/xxx`;
      document.body.appendChild(a);
      a.click();
    },
}
举报

相关推荐

0 条评论