导入

<el-upload
  class="uploadExcel"
  :action="baseUrl + 'Index/Index/drugin'"
  :headers="headers"
  :limit="1"
  name="excel"
  :on-success="excelSuccess"
  :show-file-list="false"
  accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel"
>
  <el-button type="primary" size="mini">批量导入</el-button>
</el-upload>
var Credentials = localStorage.getItem("HTTP_VIPID_KEY");//在缓存中取用户的标识
import axios from "axios";
export default {
  data() {
    return {
      baseUrl: "",
      headers: {
        Credentials: Credentials // 将缓存中取到的标识放到header里
      }
    };
  },
}
//导入成功执行的函数
excelSuccess(res, file) {
      console.log(res);
      // var reg = /<pre.+?>(.+)<\/pre>/g;
      // var result = data.match(reg);
      // data = RegExp.$1;
      if (res.status) {
        this.$notify({
          message: "导入成功",
          type: "success"
        });
      } else {
        this.$notify({
          message: "导入失败",
          type: "warning"
        });
      }
    }

导出

<el-button type="primary" @click="exportMedical" size="mini"
  >导出</el-button
>
import axios from "axios";
export default {
    methods:{
        exportMedical() {
            axios({
                url:
                this.$global.baseUrl +
                  "Index/Index/expdrug?id=" +
                  this.chooseArr.join(",") +
                  "&name=" +
                  this.medicalForm.name +
                  "&supplier=" +
                  this.medicalForm.supplier,
                headers: {
                  Credentials: localStorage.getItem("HTTP_VIPID_KEY")
                },
                method: "get",
                responseType: "blob"
          }).then(data => {
            console.log("明细导出");
            const url = window.URL.createObjectURL(data.data);
            const a = document.createElement("a");
            a.href = url;
            a.download = "药品列表.xls";
            document.body.appendChild(a);
            a.click();
            window.URL.revokeObjectURL(url);
            document.body.removeChild(a);
      });
    }
}

上传照片

<el-upload
    class="avatar-uploader"
    :action="uploadUrl"
    :show-file-list="false"
    :on-success="uploadbimg"
    name="image"
    >
    <img v-if="fristForm.bimg" :src="fristForm.bimg" class="avatar" />
    <i v-else class="el-icon-plus avatar-uploader-icon"></i>
</el-upload>
uploadbimg(res, file) {
  console.log(res.status);
  if (res.status) {
    this.fristForm.bimg = res.url;
    console.log(this.fristForm);
  }
},

houqq
245 声望14 粉丝