久久久精品一区ed2k-女人被男人叉到高潮的视频-中文字幕乱码一区久久麻豆樱花-俄罗斯熟妇真实视频

element-uiupload組件多文件上傳的示例代碼

之前有一篇寫(xiě)的如何同時(shí)傳遞form表單及upload組件文件,如果有多個(gè)upload文件該如何傳遞呢

創(chuàng)新互聯(lián)主營(yíng)大田網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,app軟件開(kāi)發(fā),大田h5微信小程序搭建,大田網(wǎng)站營(yíng)銷(xiāo)推廣歡迎大田等地區(qū)企業(yè)咨詢(xún)

上代碼

html

<el-form ref="newform" :model="newform" :rules="rules">
    <el-form-item prop="expName" label="">
     <el-input v-model="newform.expName" placeholder="" >
     </el-input>
    </el-form-item>
    <el-form-item prop="expSn" label="">
     <el-input v-model="newform.expSn" placeholder="" >
     </el-input>
    </el-form-item>
    <el-form-item label='' prop="groupName">
     <el-select v-model="newform.groupName" placeholder=""  @change="newSelectGroup($event)">
      <el-option
      v-for="item in groupOptions"
      :key="item.groupId"
      :label="item.groupName"
      :value="item.groupId">
      </el-option>
     </el-select>
    </el-form-item>
    <el-form-item label="" prop="subGroupName">
     <el-select v-model="newform.subGroupName" placeholder=""  @change="newSelectSubGroup($event)">
      <el-option
      v-for="item in subGroupOptions"
      :key="item.subGroupId"
      :label="item.subGroupName"
      :value="item.subGroupId">
      </el-option>
     </el-select>
    </el-form-item>
    <el-form-item label="" prop="expvmDifficulty">
     <el-rate v-model="newform.expvmDifficulty" :max="5" ></el-rate>
    </el-form-item>
    <el-form-item label="" prop="expvmInstruction">
     <el-upload
      class="upload-demo"
      drag
      ref="uploadhtml"
      :action="upload_url"
      :auto-upload="false"
      :before-upload="newHtml"
      accept=".html, .htm">
      <div class="el-upload__text">將文件拖到此處,或<em>點(diǎn)擊上傳</em></div>
      <div slot="tip" class="el-upload__tip">實(shí)驗(yàn)信息上傳,只能傳(.html/.htm)文件</div>
     </el-upload>
    </el-form-item>
    <el-form-item label="" prop="expvmFiles">
     <el-upload
      class="upload-demo"
      drag
      ref="uploadfile"
      :action="upload_url"
      :auto-upload="false"
      :before-upload="newFiles"
      multiple>
      <div class="el-upload__text">將文件拖到此處,或<em>點(diǎn)擊上傳</em></div>
      <div slot="tip" class="el-upload__tip">實(shí)驗(yàn)信息附件上傳,只能傳(.file)文件</div>
     </el-upload>
    </el-form-item>
    <el-form-item label="" prop="expvmVideo">
     <el-upload
      class="upload-demo"
      drag
      ref="uploadvideo"
      :action="upload_url"
      :auto-upload="false"
      :before-upload="newVideo"
      accept=".mp4">
      <div class="el-upload__text">將文件拖到此處,或<em>點(diǎn)擊上傳</em></div>
      <div slot="tip" class="el-upload__tip">實(shí)驗(yàn)視頻上傳,只能傳(.mp4)文件</div>
     </el-upload>
    </el-form-item>
    <el-form-item >
     <el-button type="primary" @click="newSubmitForm()" class="yes-btn">
     確 定
     </el-button>
     <el-button @click="resetForm('newform')">
     重 置
     </el-button>
    </el-form-item>
   </el-form>

js

data () {
  return {
    upload_url: 'aaa',    // 隨便填一個(gè),但一定要有
    uploadForm: new FormData(),  // 一個(gè)formdata
   rules: {},   // 用到的規(guī)則
   newform: {
    expName: '',
    groupName: '',
    expSn: '',
    subGroupName: '',
    expvmDifficulty: 1
   }
  }
 }

methods

newSubmitForm () {
   this.$refs['newform'].validate((valid) => {
    if (valid) {
     this.uploadForm.append('expName', this.newform.expName)
     this.uploadForm.append('expSn', this.newform.expSn)
     this.uploadForm.append('groupId', this.newgroupId)
     this.uploadForm.append('subGroupId', this.newsubgroupId)
     this.uploadForm.append('expvmDifficulty', this.newform.expvmDifficulty)
     
     newExp(this.uploadForm).then(res => {
      if (res.code === 400) {
       this.$message.error(res.error)
      } else if (res.code === 200) {
       this.$message.success('上傳成功!')
      
      }
     })
     this.$refs.uploadhtml.submit()  // 提交時(shí)觸發(fā)了before-upload函數(shù)
     this.$refs.uploadfile.submit()
     this.$refs.uploadvideo.submit()
     
    } else {
     console.log('error submit!!')
     return false
    }
   })
  },
  newHtml (file) {  // before-upload
   this.uploadForm.append('html', file)
   return false
  },
  newFiles (file) {
   this.uploadForm.append('file[]', file)
   return false
  },
  newVideo (file) {
   this.uploadForm.append('video', file)
   return false
  }
newExp函數(shù)是作為一個(gè)前后端交互的函數(shù)
export function newExp (data) {
 return axios({
  method: 'post', // 方式一定是post
  url: '你的后臺(tái)接收函數(shù)路徑',
  timeout: 20000,
  data: data    // 參數(shù)需要是單一的formData形式
 })
}

PHP代碼,后臺(tái)接收

public function newExp() {
   $param = $this->request->post();     // 獲取頁(yè)面表單傳值
   $files = $this->request->file();     // 接收到的文件
 }

注意

this.uploadForm.append('file[]', file)

這里是接收多文件一定要是數(shù)組形式的file[]

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。

當(dāng)前標(biāo)題:element-uiupload組件多文件上傳的示例代碼
轉(zhuǎn)載源于:http://sd-ha.com/article6/jiieig.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站維護(hù)、建站公司、商城網(wǎng)站網(wǎng)站內(nèi)鏈、響應(yīng)式網(wǎng)站、品牌網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

網(wǎng)站托管運(yùn)營(yíng)