关于Avue的一些坑(慢慢更新

1.图片上传回调

       {
            type: "upload",
            label: "排水证图片",
            prop: "drainWaterCardImage",
            span: 24,
            limit: 2,
            action: "/api/siping-resource/oss/endpoint/put-file-attach",
            listType: "picture-card",
            limit无效的时候picture-img 就改为card
            showFileList: true,
            dataType: "string",
            accept: "image/*",
            tip: "只能上传JPG、jpeg、PNG文件",
            loadText: "图片上传中,请稍等",
            hide: true,
            propsHttp: {
                res: "data",
                url: "link",
            },
        },

		vue文件
       <avue-crud ref="crud"
               v-model="form"
               :option="tableInfo.option"
               :data="tableInfo.data"
               :page.sync="tableInfo.page"
               :search.sync="tableInfo.query"
               :table-loading="tableInfo.loading"
               :before-open="beforeOpen"
               :defaults.sync="tableInfo.defaults"
               @row-del="rowDel"
               @row-update="rowUpdate"
               @row-save="rowSave"
               @search-change="searchChange"
               @search-reset="searchReset"
               @current-change="currentChange"
               @size-change="sizeChange"
               @refresh-change="onLoad"
               @on-load="onLoad"
               :upload-after="uploadAfter">


这个是上传upload的回调方法 上传文件或者图片都可以在这里进行res的处理
 uploadAfter (res, done, loading, column) {

      console.log(this.form);

      console.log(res);
      this.form.drainWaterCardImage = res.name
      console.log(this.form);

      console.log(column);
      // this.excelBox = false;
      // this.refreshChange();
      done();
    },

2.文件上传(xls,pdf,word之类)回显下载

avue-crud增加方法
beforeOpen处理一下获得的数据
属性配置页面 不要加string之类的参数 配置name为文件名字

:upload-preview="uploadPreview"

methods:{
    uploadPreview(file, column, done) {
      console.log(file);
      this.download(file.url, file.name);
    },
    download(url, fileName) {
      var xhr = new XMLHttpRequest();
      xhr.open("GET", url, true);
      xhr.responseType = "blob";
      xhr.onload = function () {
        if (this.status === 200) {
          var blob = new Blob([this.response]);
          var blobUrl = window.URL.createObjectURL(blob);
          var a = document.createElement("a");
          a.href = blobUrl;
          a.download = fileName;
          a.click();
          window.URL.revokeObjectURL(blobUrl);
        }
      };
      xhr.send();
    },
   },
   
    beforeOpen(done, type) {
      if (["edit", "view"].includes(type)) {
        infoDetail(this.form.id).then((res) => {
          if (res.data.code === 200) {
   
            this.form = res.data.data;
            if (this.form.fileUrl && this.form.fileUrl != "") {
              this.form.attachFileInfoListUrl = [
                {
                  label:
                    this.form.fileName && this.form.fileUrl
                      ? this.form.fileName
                      : "文件",
                  value: this.form.fileUrl,
                },
              ];
            }
          }
        });
      }
      done();
    },
		
		属性配置页面 
  {
        type: "upload",
        label: "上传附件",
        prop: "attachFileInfoList",
        span: 24,
        labelWidth: 100,
        loadText: "文件上传中,请稍等",
        accept: ".xls,.xlsx,.txt,.doc,.docx,.pdf",
        propsHttp: {
          res: "data",
          attachId: "attachId",
          fileExtension: "name",
          fileSize: "fileSize",
          url: "link",
          name: "originalName",
        },
        action: "/api/newwater-resource/oss/endpoint/put-file-attach",
        row: true,
        hide: true,
      },

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值