欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

iview Upload組件多個文件上傳的示例代碼

 更新時間:2018年09月30日 10:48:44   作者:半截肥皂  
這篇文章主要介紹了iview Upload組件多個文件上傳的示例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

使用  iview Upload 上傳組件 手動上傳 包括單個文件和多個文件

思路:創(chuàng)建一個數(shù)組 把需要上傳的文件 push到這個數(shù)組里面

1.引用組件

2.手動上傳,根據(jù)官方文檔 設(shè)置:before-upload ="handleUpload"等于false

(1).:before-upload 是 iview Upload 上傳組件的一個屬性 設(shè)置返回值為 false 可以阻止默認(rèn)上傳方式(自動上傳模式)

(2).handleUpload 是方法  *備注:代碼在最后面

3.上傳方法     

       //創(chuàng)建 formData 對象
          let formData = new FormData();
          //向 formData 對象中添加文件--這是其他參數(shù)
          formData.append('jsid', _jsid);

          //多個文件上傳----------重點(diǎn)----需要吧已經(jīng)存儲到本地的文件加入 formData所以這里用for循環(huán)

          for(var i=0; i< that.file.length; i++){ 
           formData.append("uploadFile",that.file[i]);  // 文件對象  
          } 

HTML代碼如下:

<FormItem label="應(yīng)標(biāo)資料" v-show="islook">
          <template>
            <Upload
              multiple
              ref="upload"
              type="drag"
              :format="['docx','doc','txt', 'pdf']"
              :max-size="5000"
              :before-upload="handleUpload"
              :action="http">
              <div style="padding: 20px 0">
                <Icon type="ios-cloud-upload" size="52" style="color: #3399ff"></Icon>
                <p>點(diǎn)擊或者拖拽到此次上傳文件</p>
              </div>
            </Upload>
            <div>
              <ul class="file-list" v-for="(list,index) in file" :key="index">
                <li>文件名: <span style="font-size:15px;">{{ list.name }}</span> <Icon type="ios-close" size="20" style="float:right;" @click="delFileList(index)"></Icon></li>
              </ul>
            </div>
          </template>
        </FormItem>


        <FormItem v-show="islookshenghe">
          <h3>已經(jīng)提交數(shù)據(jù)-正在等待審核</h3>
          <Button type="primary" @click="gobackfanhui">返回</Button>
        </FormItem>

        <FormItem v-show="islook">
          <Button type="primary" :loading="loading2" icon="ios-power" @click="upload">
            <span v-if="!loading2">接受并提交應(yīng)標(biāo)信息</span>
            <span v-else>正在上傳文件中...</span>
          </Button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

          <p style="color:red;font-size:15px;" v-show="isfiletihsi">請上傳文件</p>
        </FormItem>

JS代碼

delFileList(index){
        let that = this;
        that.file.splice(index, 1);
        
        console.log(that.file);
      }
handleUpload (file) {
        let that = this;
        if(that.file.length >= 5){
          this.$Message.info("最多只能上傳5個文件");
        }else{
          that.file.push(file);
        }
        return false;
      }

axios提交方法代碼:

upload(){
        let that = this;
        let _jsid = that.$route.query.id;
        if(that.file.length > 0){
          that.loading2 = true;
          //創(chuàng)建 formData 對象
          let formData = new FormData();
          //向 formData 對象中添加文件
          formData.append('jsid', _jsid);

          //多個文件上傳
          for(var i=0; i< that.file.length; i++){ 
           formData.append("uploadFile",that.file[i]);  // 文件對象  
          } 

          let config = {
           headers: {
            'Content-Type': 'multipart/form-data'
           }
          }

          axios.post(that.http + "/shweb/gys/gysmsge/gysuploads.action", formData, {
                timeout: 10000,
                headers: {
                  'Content-Type': 'multipart/form-data'
                }
              }).then(function (rdata) {
                that.loading2 = false;
                if(rdata.data == "0"){
                  that.islook = false;
                  that.islookshenghe = true;
                }
                console.log(rdata);
              }).catch(function (error) {
                that.loading2 = false;
               that.$Message.error('服務(wù)器錯誤' + error);
              });
        }else{
          that.$Message.error("請至少上傳一個文件");
        }
      }

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論