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

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

 更新時(shí)間:2018年10月17日 10:16:25   作者:bettyjones  
這篇文章主要介紹了element-ui upload組件多文件上傳的示例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

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

上代碼

html

<el-form ref="newform" :model="newform" :rules="rules">
    <el-form-item prop="expName" label="">
     <el-input v-model="newform.expName" placeholder="" style="width:75%">
     </el-input>
    </el-form-item>
    <el-form-item prop="expSn" label="">
     <el-input v-model="newform.expSn" placeholder="" style="width:75%">
     </el-input>
    </el-form-item>
    <el-form-item label='' prop="groupName">
     <el-select v-model="newform.groupName" placeholder="" style="width:75%" @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="" style="width:75%" @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" style="line-height: 2;"></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 style="text-align:center">
     <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',    // 隨便填一個,但一定要有
    uploadForm: new FormData(),  // 一個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ù)是作為一個前后端交互的函數(shù)
export function newExp (data) {
 return axios({
  method: 'post', // 方式一定是post
  url: '你的后臺接收函數(shù)路徑',
  timeout: 20000,
  data: data    // 參數(shù)需要是單一的formData形式
 })
}

PHP代碼,后臺接收

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

注意

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

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

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

相關(guān)文章

  • Vue3+antDesignVue實(shí)現(xiàn)表單校驗(yàn)的方法

    Vue3+antDesignVue實(shí)現(xiàn)表單校驗(yàn)的方法

    這篇文章主要為大家詳細(xì)介紹了基于Vue3和antDesignVue實(shí)現(xiàn)表單校驗(yàn)的方法,文中的示例代碼講解詳細(xì),具有一定的參考價(jià)值,需要的小伙伴可以了解下
    2024-01-01
  • vue使用百度地圖報(bào)錯BMap?is?not?defined問題及解決

    vue使用百度地圖報(bào)錯BMap?is?not?defined問題及解決

    這篇文章主要介紹了vue使用百度地圖報(bào)錯BMap?is?not?defined問題及解決,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-10-10
  • Vue中父組件向子組件通信的方法

    Vue中父組件向子組件通信的方法

    可以使用props將父組件的數(shù)據(jù)傳給子組件。子組件在接受數(shù)據(jù)時(shí)要顯示聲明props。下面通過一個例子給大家介紹Vue中父組件向子組件通信的方法,需要的朋友參考下吧
    2017-07-07
  • Vue無后端配合實(shí)現(xiàn)導(dǎo)出功能的示例代碼

    Vue無后端配合實(shí)現(xiàn)導(dǎo)出功能的示例代碼

    這篇文章主要為大家詳細(xì)介紹了Vue如何在無后端配合的情況下實(shí)現(xiàn)導(dǎo)出功能,文中的示例代碼簡潔易懂,有需要的小伙伴可以跟隨小編一起了解一下
    2024-01-01
  • vue2.0 實(shí)現(xiàn)導(dǎo)航守衛(wèi)(路由守衛(wèi))

    vue2.0 實(shí)現(xiàn)導(dǎo)航守衛(wèi)(路由守衛(wèi))

    vue-route 提供的 beforeRouteUpdate 可以方便地實(shí)現(xiàn)導(dǎo)航守衛(wèi)(navigation-guards)。這篇文章主要介紹了vue2.0 實(shí)現(xiàn)導(dǎo)航守衛(wèi)(路由守衛(wèi))的相關(guān)知識,需要的朋友可以參考下
    2018-05-05
  • vue中路由router配置步驟詳解

    vue中路由router配置步驟詳解

    vue的主要思想是組件化開發(fā),路由用來配置組件對應(yīng)展示路徑,本文給大家介紹vue中路由router配置步驟,創(chuàng)建路由文件——使用路由——配置路由出口,使路由配置內(nèi)容展示在頁面上,感興趣的朋友跟隨小編一起看看吧
    2023-12-12
  • element-ui中頁面縮放時(shí)table表格內(nèi)容錯位的解決

    element-ui中頁面縮放時(shí)table表格內(nèi)容錯位的解決

    這篇文章主要介紹了element-ui中頁面縮放時(shí)table表格內(nèi)容錯位的解決方案,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-08-08
  • Vue中.env、.env.development及.env.production文件說明

    Vue中.env、.env.development及.env.production文件說明

    這篇文章主要給大家介紹了關(guān)于Vue中.env、.env.development及.env.production文件說明的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用vue具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2022-09-09
  • vue中各種deep的區(qū)別解析

    vue中各種deep的區(qū)別解析

    在Vue3中,推薦使用::deep作為深度選擇器,它比Vue2中的::v-deep語法更簡潔,::v-deep、::deep、:deep()、&gt;&gt;&gt;和/deep/都是用于穿透組件作用域的選擇器,但Vue3更傾向于使用::deep或:deep(),感興趣的朋友跟隨小編一起看看吧
    2024-10-10
  • Vue超詳細(xì)講解重試機(jī)制示例

    Vue超詳細(xì)講解重試機(jī)制示例

    這篇文章主要介紹了Vue重試機(jī)制示例,重試指的是當(dāng)加載出錯時(shí),有能力重新發(fā)起加載組件的請求。異步組件加載失敗后的重試機(jī)制,與請求服務(wù)端接口失敗后的重試機(jī)制一樣
    2023-01-01

最新評論