vant Uploader 文件上傳,自定義參數


uploader在多組件中傳參index,方便val賦值(由服務器返回的url地址)

template:
          <van-uploader
            :after-read="afterRead(itm)"
            v-model="itm.imgs"
            :max-count="maxImgCount"
            :disabled="disabled"
          ></van-uploader>

js:itm是傳入進來的,方便val賦值。file是after-read 文件讀取完成后的回調函數所帶的默認參數

   afterRead(itm) {
      return file => {
        this.$toast.loading({ duration: 0 });
        this.axios({
          method: "post",
          url: "/api/Upload/List",
          data: JSON.stringify({
            Id: file.content
          })
        })
          .then(({ code, data, msg }) => {
            this.$toast.clear();
            if (code >= 0) {
              var imgs = itm.imgs || [];
              var i = imgs.length;
              if (i <= 0) {
                imgs = [{ url: data }];
              } else {
                imgs[i - 1] = { url: data };
              }
              itm.imgs = imgs;

              var url = [];
              for (const row of imgs) {
                url.push(row.url);
              }
              itm.Val = url.join(",");
            } else {
              this.$toast(msg);
            }
          })
          .catch(err => {
            this.$toast.clear();
            this.$toast(`${err}`);
          });
      };
    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM