中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

vue+element?upload上傳帶參數的方法

發布時間:2022-04-25 10:27:51 來源:億速云 閱讀:2809 作者:iii 欄目:開發技術

今天小編給大家分享一下vue+element upload上傳帶參數的方法的相關知識點,內容詳細,邏輯清晰,相信大部分人都還太了解這方面的知識,所以分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后有所收獲,下面我們一起來了解一下吧。

element upload上傳帶參數

<el-button  size="small" type="success" @click="submitUpload">保存</el-button>
   <el-upload
    class="upload-demo"
    ref="upload"
    :action="action()"
    :on-preview="handlePreview"
    :before-upload="beforeUpload"  
    :data="uploadData"    
    :on-error = "error"
    :on-success="successResave"
    :on-remove="handleRemove"
    :file-list="fileList"
    :auto-upload="false">
    <el-button slot="trigger" size="small" type="primary">選取文件</el-button>
    <!-- <el-button  size="small" type="success" @click="submitUpload">上傳到服務器</el-button> -->
    <!-- <div slot="tip" class="el-upload__tip">只能上傳jpg/png文件,且不超過500kb</div> -->
    </el-upload>

data里面參數

uploadData:null,

methods里面

action(){
       return this.portC+"uplodResultsScore"
     },
     //上傳
     submitUpload() {
 
        this.$refs.upload.submit();
      },
      handleRemove(file, fileList) {
        console.log(file, fileList);
      },
      handlePreview(file) {
 
        console.log(file);
      },
      beforeUpload (file) {     
          
         this.uploadData = {dstype:this.proType,name:this.mobanname,dsmark:this.value5,};
             console.log(this.uploadData)
            let promise = new Promise((resolve) => {
                this.$nextTick(function () {
                    resolve(true);
                });
            });
            return promise; //通過返回一個promis對象解決
     },
     //上傳成功鉤子
     successResave(response, file, fileList){
           console.log(response)
           if(response.code==10001){
              alert("保存成功")  
               this.proType="";
               this.mobanname="";
               this.value5="";
               this.$router.push("/moban")
           }
     },
    //失敗鉤子
     error(response, file, fileList){
           console.log(response)
     },
     //選擇家化實效
      selectType(val){
         console.log(val)
         if(val==1){
             this.$router.push("/new")
         }else{
             this.$router.push("/new1")
         }
      },

效果圖

vue+element?upload上傳帶參數的方法

element上傳函數帶參數,自定義傳參

下面這是標簽

可以看出來 :

http-request="(params) =>beforeMasterPictureUpload(params,‘ruleForm',fileList0)"

http-request 傳遞參數的方法 是可以這樣寫的,其他方法一樣,但是如果寫錯少些可能會導致覆蓋原來的方法。

<el-upload :class="{hidesse:hideUpload0,'avatar-uploader':true}" 
                        multiple action="這里不需要填或者隨便寫"
                        list-type="picture-card" :before-upload="beforeAvatarUpload"
                        :on-preview="(params) =>handlePictureCardPreview(params,'ruleForm',fileList0)"
                        :http-request="(params) =>beforeMasterPictureUpload(params,'ruleForm',fileList0)"
                        :on-change="(params,fileList) =>onChangeMaster(params,fileList,'ruleForm','fileList0')"
                        :on-exceed="OnExceed"
                        :on-remove="(params) =>handleRemove(params,'ruleForm',fileList0,'fileList0')" :limit="5"
                        :file-list="fileList0" @click="titext">
                        <i class="el-icon-plus"></i>
                    </el-upload>

下面是JS 接受方法 同樣 我們拿 http-request 這個方法做例子

beforeMasterPictureUpload(params, fromData, prop) {
    console.log('----aaaa', this.fileList);
    console.log('file', params, fromData, prop);
}

大家可以輸出看看結果 是否有拿到你上面傳遞過來的字符串或者是值

我將源碼放上

HTML標簽

<el-upload :class="{hidesse:hideUpload0,'avatar-uploader':true}" 
                        multiple action="這里不需要填或者隨便寫"
                        list-type="picture-card" :before-upload="beforeAvatarUpload"
                        :on-preview="(params) =>handlePictureCardPreview(params,'ruleForm',fileList0)"
                        :http-request="(params) =>beforeMasterPictureUpload(params,'ruleForm',fileList0)"
                        :on-change="(params,fileList) =>onChangeMaster(params,fileList,'ruleForm','fileList0')"
                        :on-exceed="OnExceed"
                        :on-remove="(params) =>handleRemove(params,'ruleForm',fileList0,'fileList0')" :limit="5"
                        :file-list="fileList0" @click="titext">
                        <i class="el-icon-plus"></i>
                    </el-upload>

JS語句

// 主圖上傳之前
                beforeAvatarUpload(file) {
                    console.log('主圖上傳之前:', file)
                    const idJPG =
                        file.type === "image/jpeg" || "image/gif" || "image/png" || "image/bmp";
                    if (!idJPG) {
                        this.$message.error(
                            '123123'
                        );
                    }
                    return idJPG;
                },
                // 圖片觸發
                onChangeMaster(file, fileList, fromData, prop) {
                    // fileList 當前上傳框的數據 
                    switch (prop) {
                        case 'fileList0':
                            { this.hideUpload0 = fileList.length >= this.limitCount; }
                            break;
                        case 'fileList1':
                            { this.hideUpload1 = fileList.length >= this.limitCount; }
                            break;
                        case 'fileList2':
                            { this.hideUpload2 = fileList.length >= this.limitCount; }
                            break;
                        case 'fileList3':
                            { this.hideUpload3 = fileList.length >= this.limitCount; }
                            break;
                        case 'fileList4':
                            { this.hideUpload4 = fileList.length >= this.limitCount; }
                            break;
                        case 'fileList5':
                            { this.hideUpload6 = fileList.length >= this.limitCount; }
                            break;
                        default:
                            break;
                    }
                    console.log('判斷一次', file, fileList, this.fileList0)
                    if (this.inde > 0) {
                        return
                    } else {
                        //let existFile = fileList.slice(0, fileList.length - 1).find(f => f.name === file.name)
                        //if (existFile) {
                           // this.inde++
                          //  console.log(existFile)
                          //  this.$message.error(
                          //      '圖片重復' + existFile.name
                        //    );
                        //    // fileList.pop()
                     //   }
                        this[prop] = fileList
                    }
                },
                // 圖片個數超出限制
                OnExceed(file, fileList) {
                    this.$message.error(
                        '每個選項最多上傳5張', "error"
                    );
                },
                handleRemove(params, fileList, prop, item) {
                    prop.forEach((obj, index) => {
                        console.log(index, obj)
                        if (params.uid == obj.uid) {
                            prop.splice(index, 1)
                        }
                    })
                    console.log('刪除后的數組', prop);
                    setTimeout(() => {
                        switch (item) {
                            case 'fileList0':
                                { this.hideUpload0 = prop.length >= this.limitCount; }
                                break;
                            case 'fileList1':
                                { this.hideUpload1 = prop.length >= this.limitCount; }
                                break;
                            case 'fileList2':
                                { this.hideUpload2 = prop.length >= this.limitCount; }
                                break;
                            case 'fileList3':
                                { this.hideUpload3 = prop.length >= this.limitCount; }
                                break;
                            case 'fileList4':
                                { this.hideUpload4 = prop.length >= this.limitCount; }
                                break;
                            case 'fileList5':
                                { this.hideUpload6 = prop.length >= this.limitCount; }
                                break;
                            default:
                                break;
                        }
                        console.log(prop.length >= this.limitCount)
                    }, 1000)
                    // this.fileList = [];
                    this.dialogImageUrl = '';
                },
                handlePictureCardPreview(file, fromData, prop) {
                    console.log(file, fromData, prop)
                    this.dialogImageUrl = file.url;
                    this.dialogVisible = true;
                },
                beforeMasterPictureUpload(params, fromData, prop) {
                    console.log('----aaaa', this.fileList);
                    console.log('file', params, fromData, prop);
                    
                },

這是需求案列

vue+element?upload上傳帶參數的方法

以上就是“vue+element upload上傳帶參數的方法”這篇文章的所有內容,感謝各位的閱讀!相信大家閱讀完這篇文章都有很大的收獲,小編每天都會為大家更新不同的知識,如果還想學習更多的知識,請關注億速云行業資訊頻道。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

六枝特区| 余庆县| 察隅县| 湘潭市| 旬邑县| 大方县| 东源县| 神农架林区| 剑阁县| 长葛市| 定襄县| 宾川县| 安陆市| 陵水| 高要市| 滁州市| 巴里| 雷州市| 黄陵县| 伊宁县| 罗城| 朔州市| 繁昌县| 开封县| 商水县| 山东省| 卢湾区| 顺昌县| 邵武市| 宁海县| 同江市| 根河市| 古浪县| 灌阳县| 舒城县| 拜城县| 平武县| 长兴县| 彭州市| 金门县| 奉节县|