美文网首页
vue下载文件导入导出

vue下载文件导入导出

作者: 洪锦一 | 来源:发表于2022-04-23 13:13 被阅读0次

下载文件

downloadExcelFile() {
  // 创建隐藏的可下载链接
  var eleLink = document.createElement("a");
  eleLink.download = "加工费.xls";
  eleLink.style.display = "none";
  // 字符内容转变成blob地址
  eleLink.href = "/jgf.xls";
  // 触发点击
  document.body.appendChild(eleLink);
  eleLink.click();
  // 然后移除
  document.body.removeChild(eleLink);
},

导出文件

exportExcel() {
  // 导出
  var parameter = {
    Salesway: this.formSearch.Salesway,
    ProductStyle:
      this.formSearch.ProductStyle === ""
        ? -1
        : this.formSearch.ProductStyle,
    ProductGroup:
      this.formSearch.ProductGroup === ""
        ? -1
        : this.formSearch.ProductGroup,
    Technology:
      this.formSearch.Technology === "" ? -1 : this.formSearch.Technology,
    Product: this.formSearch.Product === "" ? -1 : this.formSearch.Product,
    gic: this.formSearch.gic,
  };
  this.$request.exportCMTList(parameter).then((response) => {
    var eleLink = document.createElement("a");
    eleLink.download = "加工费.xls";
    eleLink.style.display = "none";
    // 字符内容转变成blob地址
    eleLink.href = response.successMessage;
    // 触发点击
    document.body.appendChild(eleLink);
    eleLink.click();
    // 然后移除
    document.body.removeChild(eleLink);
  });
},

导入文件

<el-upload
  ref="upload"
  :headers="{ Authorization: tokenID }"
  class="upload-demo"
  :action="url"
  multiple
  :limit="3"
  :on-success="handleSuccess"
  :file-list="fileList">
  <el-button size="mini" >导入</el-button>
</el-upload>

data() {
    return {
        url: config.uploadXLSFiles, //导入加工费  uploadJGFFilehttp://139.224.204.12:8083/api/VSetting/VSetting_Import_CMTList
    }
}

handleSuccess(res, file, fileList) {
  // 文件上传
  if (res.isError) {
    this.$message({
      type: "error",
      message: "上传失败" + res.errorMessage,
    });
  } else {
    this.$message({
      type: "success",
      message: "上传成功!",
    });
  }
  this.$refs.upload.clearFiles(); //清除数据
  this.dialogVisibleExcelDR = false; //页面关闭
  this.getListData(); //刷新数据
},

相关文章

网友评论

      本文标题:vue下载文件导入导出

      本文链接:https://www.haomeiwen.com/subject/boraertx.html