最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue element el-form 多級(jí)嵌套驗(yàn)證的實(shí)現(xiàn)示例

 更新時(shí)間:2022年08月12日 11:52:54   作者:zhang070514  
本文主要介紹了vue element el-form 多級(jí)嵌套驗(yàn)證的實(shí)現(xiàn)示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

最近在做項(xiàng)目時(shí)遇到這樣一個(gè)需求,一個(gè)form表單里面有兩個(gè)字段數(shù)量不固定,可以動(dòng)態(tài)的增刪,在提交的時(shí)候不管數(shù)量有多少都需要驗(yàn)證,頁(yè)面效果如下:

form表單對(duì)應(yīng)的數(shù)據(jù)結(jié)構(gòu)如下:

      voucherInfo: {
        cash: [
          {
            cashNum: '', // 押金流水號(hào)
            cashPayType: null, // 押金支付類型
          }
        ],
        cashPayTime: '', // 押金支付時(shí)間
        cashPayVoucher: [], // 押金支付憑證
        commissionNum: '', // 傭金流水號(hào)
        commissionPayType: null, // 傭金支付方式
        commissionPayTime: '', // 傭金支付時(shí)間
        commissionPayVoucher: [], // 傭金支付憑證
        remark: '' // 備注
      }

在這里主要考慮的就是如何驗(yàn)證voucherInfo的第一個(gè)字段,它是一個(gè)數(shù)組,數(shù)組里面又是一個(gè)對(duì)象,我們要驗(yàn)證這個(gè)對(duì)象的每個(gè)屬性,簡(jiǎn)而言之,就是驗(yàn)證對(duì)象里面的數(shù)組里面的對(duì)象屬性。

方法一:el-form里面再嵌套一個(gè)el-form

  <el-form
      ref="voucherForm"
      :rules="voucherRule"
      :model="voucherInfo"
      label-width="140px"
    >
      <div
        v-for="(item, index) in voucherInfo.cash"
        :key="index"
      >
      	<!-- 嵌套的el-form   model綁定的是voucherInfo.cash里面的對(duì)象 -->
      	<!-- 又定義了一個(gè)rules :rules="subVoucherRule"-->
        <el-form
          ref="subVoucherForm"
          :model="item"
          :rules="subVoucherRule"
          label-width="140px"
        >
          <el-row>
            <el-col :span="6">
              <el-form-item
                prop="cashNum"
                :label="'押金流水號(hào)' + (index + 1)"
              >
               <el-input
                v-model="item.cashNum"
                palceholder="請(qǐng)輸入"
               >
               </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item
                :label="'押金支付方式' + (index + 1)"
                prop="cashPayType"
              >
                <el-select
                  v-model="item.cashPayType"
                  placeholder="請(qǐng)選擇"
                >
                  <el-option
                    v-for="i in cashPayTypeOptions"
                    :label="i.label"
                    :value="i.value"
                    :key="i.value"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-button
                type="primary"
                icon="el-icon-minus"
                circle
                @click="handleMinusClick(index)"
              >
              </el-button>
              <el-button
                type="primary"
                icon="el-icon-plus"
                circle
                @click="handleAddClick()"
              >
              </el-button>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <el-row>
        <el-col :span="6">
          <el-form-item label="押金支付時(shí)間" prop="cashPayTime">
            <el-date-picker
              v-model="voucherInfo.cashPayTime"
              placeholder="請(qǐng)選擇"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="上傳支付憑證" prop="cashPayVoucher">
            <el-upload
              class="avatar-upload"
              action=""

            >
              <img v-if="voucherInfo.cashPayVoucher.length" src="" alt="" class="avatar">
              <i v-else class="el-icon-plus avatar-uploader-icon"></i>
            </el-upload>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6">
          <el-form-item label="傭金流水號(hào)" prop="commissionNum">
            <el-input
              v-model="voucherInfo.commissionNum"
              placeholder="請(qǐng)輸入"
            >
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="傭金支付方式" prop="commissionPayType">
            <el-select
              v-model="voucherInfo.commissionPayType"
              placeholder="請(qǐng)選擇"
            >
              <el-option
                v-for="item in commissionPayTypeOptions"
                :label="item.label"
                :value="item.value"
                :key="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6">
          <el-form-item label="傭金支付時(shí)間" prop="commissionPayTime">
            <el-date-picker
              v-model="voucherInfo.commissionPayTime"
              placeholder="請(qǐng)選擇"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="傭金支付憑證" prop="commissionPayVoucher">
            <el-upload
              class="avatar-upload"
              action=""

            >
              <img v-if="voucherInfo.commissionPayVoucher.length" src="" alt="" class="avatar">
              <i v-else class="el-icon-plus avatar-uploader-icon"></i>
            </el-upload>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="備注">
            <el-input
              type="textarea"
              placeholder="請(qǐng)輸入"
              v-model="voucherInfo.remark"
            >
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

驗(yàn)證規(guī)則:

      voucherRule: {
        cashPayTime: [{ required: true, message: '請(qǐng)選擇押金支付時(shí)間', trigger: 'change'}],
        cashPayVoucher: [{ required: true, message: '請(qǐng)上傳押金支付憑證', trigger: 'change'}],
        commissionNum: [{ required: true, message: '請(qǐng)輸入傭金流水號(hào)', trigger: 'blur'}],
        commissionPayType: [{ required: true, message: '請(qǐng)選擇傭金支付方式', trigger: 'change'}],
        commissionPayTime: [{ required: true, message: '請(qǐng)選擇傭金支付時(shí)間', trigger: 'change'}],
        commissionPayVoucher: [{ required: true, message: '請(qǐng)上傳傭金支付憑證', trigger: 'change'}],
      },
      subVoucherRule: {
        cashNum: [{ required: true, message: '請(qǐng)輸入押金流水號(hào)', trigger: 'blur'}],
        cashPayType: [{ required: true, message: '請(qǐng)選擇押金支付方式', trigger: 'change'}],
      }

提交時(shí)驗(yàn)證代碼:因?yàn)橛袃蓚€(gè)form,所以兩個(gè)都需要驗(yàn)證

 <el-form
      ref="voucherForm"
      :rules="voucherRule"
      :model="voucherInfo"
      label-width="140px"
    >
          <el-row
            v-for="(item, index) in voucherInfo.cash"
            :key="index"
          >
            <el-col :span="6">
            	<!--注意有改動(dòng)的是這里   prop動(dòng)態(tài)綁定cashNum   rules寫在了這里 -->
              <el-form-item
                :prop="'cash['+index+'].cashNum'"
                :label="'押金流水號(hào)' + (index + 1)"
                :rules="{
                  required: true, message: '請(qǐng)輸入押金流水號(hào)', trigger: 'blur'
                }"
              >
               <el-input
                v-model="item.cashNum"
                palceholder="請(qǐng)輸入"
               >
               </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
            	<!--注意有改動(dòng)的是這里   prop動(dòng)態(tài)綁定cashPayType   rules寫在了這里 -->
              <el-form-item
                :label="'押金支付方式' + (index + 1)"
                :prop="'cash['+ index +'].cashPayType'"
                :rules="{
                  required: true, message: '請(qǐng)選擇押金支付方式', trigger: 'change'
                }"
              >
                <el-select
                  v-model="item.cashPayType"
                  placeholder="請(qǐng)選擇"
                >
                  <el-option
                    v-for="i in cashPayTypeOptions"
                    :label="i.label"
                    :value="i.value"
                    :key="i.value"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-button
                type="primary"
                icon="el-icon-minus"
                circle
                @click="handleMinusClick(index)"
              >
              </el-button>
              <el-button
                type="primary"
                icon="el-icon-plus"
                circle
                @click="handleAddClick()"
              >
              </el-button>
            </el-col>
          </el-row>
      <el-row>
        <el-col :span="6">
          <el-form-item label="押金支付時(shí)間" prop="cashPayTime">
            <el-date-picker
              v-model="voucherInfo.cashPayTime"
              placeholder="請(qǐng)選擇"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="上傳支付憑證" prop="cashPayVoucher">
            <el-upload
              class="avatar-upload"
              action=""

            >
              <img v-if="voucherInfo.cashPayVoucher.length" src="" alt="" class="avatar">
              <i v-else class="el-icon-plus avatar-uploader-icon"></i>
            </el-upload>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6">
          <el-form-item label="傭金流水號(hào)" prop="commissionNum">
            <el-input
              v-model="voucherInfo.commissionNum"
              placeholder="請(qǐng)輸入"
            >
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="傭金支付方式" prop="commissionPayType">
            <el-select
              v-model="voucherInfo.commissionPayType"
              placeholder="請(qǐng)選擇"
            >
              <el-option
                v-for="item in commissionPayTypeOptions"
                :label="item.label"
                :value="item.value"
                :key="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6">
          <el-form-item label="傭金支付時(shí)間" prop="commissionPayTime">
            <el-date-picker
              v-model="voucherInfo.commissionPayTime"
              placeholder="請(qǐng)選擇"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="傭金支付憑證" prop="commissionPayVoucher">
            <el-upload
              class="avatar-upload"
              action=""

            >
              <img v-if="voucherInfo.commissionPayVoucher.length" src="" alt="" class="avatar">
              <i v-else class="el-icon-plus avatar-uploader-icon"></i>
            </el-upload>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="備注">
            <el-input
              type="textarea"
              placeholder="請(qǐng)輸入"
              v-model="voucherInfo.remark"
            >
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

方法二:直接把驗(yàn)證規(guī)則寫在html中

 <el-form
      ref="voucherForm"
      :rules="voucherRule"
      :model="voucherInfo"
      label-width="140px"
    >
          <el-row
            v-for="(item, index) in voucherInfo.cash"
            :key="index"
          >
            <el-col :span="6">
            	<!--注意有改動(dòng)的是這里   prop動(dòng)態(tài)綁定cashNum   rules寫在了這里 -->
              <el-form-item
                :prop="'cash['+index+'].cashNum'"
                :label="'押金流水號(hào)' + (index + 1)"
                :rules="{
                  required: true, message: '請(qǐng)輸入押金流水號(hào)', trigger: 'blur'
                }"
              >
               <el-input
                v-model="item.cashNum"
                palceholder="請(qǐng)輸入"
               >
               </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
            	<!--注意有改動(dòng)的是這里   prop動(dòng)態(tài)綁定cashPayType   rules寫在了這里 -->
              <el-form-item
                :label="'押金支付方式' + (index + 1)"
                :prop="'cash['+ index +'].cashPayType'"
                :rules="{
                  required: true, message: '請(qǐng)選擇押金支付方式', trigger: 'change'
                }"
              >
                <el-select
                  v-model="item.cashPayType"
                  placeholder="請(qǐng)選擇"
                >
                  <el-option
                    v-for="i in cashPayTypeOptions"
                    :label="i.label"
                    :value="i.value"
                    :key="i.value"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-button
                type="primary"
                icon="el-icon-minus"
                circle
                @click="handleMinusClick(index)"
              >
              </el-button>
              <el-button
                type="primary"
                icon="el-icon-plus"
                circle
                @click="handleAddClick()"
              >
              </el-button>
            </el-col>
          </el-row>
      <el-row>
        <el-col :span="6">
          <el-form-item label="押金支付時(shí)間" prop="cashPayTime">
            <el-date-picker
              v-model="voucherInfo.cashPayTime"
              placeholder="請(qǐng)選擇"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="上傳支付憑證" prop="cashPayVoucher">
            <el-upload
              class="avatar-upload"
              action=""

            >
              <img v-if="voucherInfo.cashPayVoucher.length" src="" alt="" class="avatar">
              <i v-else class="el-icon-plus avatar-uploader-icon"></i>
            </el-upload>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6">
          <el-form-item label="傭金流水號(hào)" prop="commissionNum">
            <el-input
              v-model="voucherInfo.commissionNum"
              placeholder="請(qǐng)輸入"
            >
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="傭金支付方式" prop="commissionPayType">
            <el-select
              v-model="voucherInfo.commissionPayType"
              placeholder="請(qǐng)選擇"
            >
              <el-option
                v-for="item in commissionPayTypeOptions"
                :label="item.label"
                :value="item.value"
                :key="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6">
          <el-form-item label="傭金支付時(shí)間" prop="commissionPayTime">
            <el-date-picker
              v-model="voucherInfo.commissionPayTime"
              placeholder="請(qǐng)選擇"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="傭金支付憑證" prop="commissionPayVoucher">
            <el-upload
              class="avatar-upload"
              action=""

            >
              <img v-if="voucherInfo.commissionPayVoucher.length" src="" alt="" class="avatar">
              <i v-else class="el-icon-plus avatar-uploader-icon"></i>
            </el-upload>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="備注">
            <el-input
              type="textarea"
              placeholder="請(qǐng)輸入"
              v-model="voucherInfo.remark"
            >
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

這樣驗(yàn)證的時(shí)候只需要驗(yàn)證一個(gè)表單就行了。
最終的實(shí)現(xiàn)效果:

 到此這篇關(guān)于vue element el-form 多級(jí)嵌套驗(yàn)證的實(shí)現(xiàn)示例的文章就介紹到這了,更多相關(guān)element el-form 多級(jí)嵌套驗(yàn)證內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 使用命令行工具npm新創(chuàng)建一個(gè)vue項(xiàng)目的方法

    使用命令行工具npm新創(chuàng)建一個(gè)vue項(xiàng)目的方法

    Vue.js 提供一個(gè)官方命令行工具,可用于快速搭建大型單頁(yè)應(yīng)用。下面小編給大家分享使用命令行工具npm新創(chuàng)建一個(gè)vue項(xiàng)目的方法,需要的朋友參考下吧
    2017-12-12
  • vueCli4如何配置vue.config.js文件

    vueCli4如何配置vue.config.js文件

    這篇文章主要介紹了vueCli4如何配置vue.config.js文件,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-03-03
  • 講解vue-router之什么是動(dòng)態(tài)路由

    講解vue-router之什么是動(dòng)態(tài)路由

    這篇文章主要介紹了講解vue-router之什么是動(dòng)態(tài)路由,詳細(xì)的介紹了什么是動(dòng)態(tài)路由,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-05-05
  • vue時(shí)間選擇控件的使用方式

    vue時(shí)間選擇控件的使用方式

    這篇文章主要介紹了vue時(shí)間選擇控件的使用方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-10-10
  • 一文解析Vue h函數(shù)到底是個(gè)啥

    一文解析Vue h函數(shù)到底是個(gè)啥

    h()函數(shù)是Vue.js中的一個(gè)工具函數(shù),用于創(chuàng)建虛擬DOM節(jié)點(diǎn),具有更高的靈活性和控制力,本文介紹Vue h函數(shù)到底是個(gè)啥,感興趣的朋友一起看看吧
    2025-02-02
  • vue 圖標(biāo)選擇器的實(shí)例代碼

    vue 圖標(biāo)選擇器的實(shí)例代碼

    本文通過(guò)實(shí)例代碼給大家介紹了vue 圖標(biāo)選擇器的相關(guān)知識(shí),圖文實(shí)例代碼相結(jié)合給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧
    2021-11-11
  • Vue清除定時(shí)器setInterval優(yōu)化方案分享

    Vue清除定時(shí)器setInterval優(yōu)化方案分享

    這篇文章主要介紹了Vue清除定時(shí)器setInterval優(yōu)化方案分享,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-07-07
  • vue 指定組件緩存實(shí)例詳解

    vue 指定組件緩存實(shí)例詳解

    keep-alive 是 Vue 內(nèi)置的一個(gè)組件,可以使被包含的組件保留狀態(tài),或避免重新渲染。這篇文章主要介紹了vue 指定組件緩存,需要的朋友可以參考下
    2018-04-04
  • vue+element表格導(dǎo)出為Excel文件

    vue+element表格導(dǎo)出為Excel文件

    這篇文章主要為大家詳細(xì)介紹了vue+element表格導(dǎo)出為Excel文件,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-09-09
  • unix時(shí)間戳轉(zhuǎn)換的方法詳解

    unix時(shí)間戳轉(zhuǎn)換的方法詳解

    將 unix 時(shí)間戳轉(zhuǎn)換為日期時(shí)間和使用日期時(shí)間轉(zhuǎn)換為 unix 時(shí)間戳,在項(xiàng)目中常常用到,其中vue中的moment庫(kù)很是方便,下面小編就來(lái)為大家講講具體使用吧
    2023-09-09

最新評(píng)論

鄂托克前旗| 陆河县| 大田县| 临漳县| 芷江| 云林县| 娄底市| 定日县| 高州市| 鄂托克旗| 潞西市| 台中市| 莱阳市| 资兴市| 会宁县| 瑞金市| 林周县| 洪洞县| 岳西县| 南溪县| 麻江县| 塔城市| 汾阳市| 元朗区| 孟连| 涿州市| 临洮县| 敦煌市| 康保县| 新竹市| 岗巴县| 恩施市| 宁海县| 宜兴市| 湾仔区| 大新县| 二连浩特市| 肥东县| 大名县| 鹤山市| 繁峙县|