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

vue elementui 動(dòng)態(tài)追加下拉框、輸入框功能

 更新時(shí)間:2024年04月27日 10:09:51   作者:鹽多碧咸。。  
這篇文章主要介紹了vue elementui 動(dòng)態(tài)追加下拉框、輸入框功能,本文通過(guò)示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧

vue elementui 動(dòng)態(tài)追加下拉框、輸入框

上代碼:

<template>
  <div>
    <el-dialog
      append-to-body
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      width="65%"
      @close="onClose"
      :modal-append-to-body="true"
      title="新建"
      custom-class="dialogBox"
      :visible.sync="dialogVisible"
      :lock-scroll="true"
      :destroy-on-close="true">
      <el-form :model="combinationInfo" label-width="90px" ref="combinationForm" :rules="rules" :inline="true" size="small">
        <el-row>
          <el-col :span="12">
            <el-form-item prop="benchMarks" label="名稱">
              <div style="color: #fb6b3f;width: 230px;">比例之和需為100%(當(dāng)前
                <span>{{benchmarkTotal}}</span>
                <span></span>%)
              </div>
              <div v-for="(item,index) in combinationInfo.benchMarks" :key="index">
                <el-select
                  style="margin-bottom: 10px;"
                  clearable
                  filterable
                  collapse-tags
                  placeholder="請(qǐng)選擇"
                  class="benchmarkSelectWidth"
                  @change="changeBenchmark"
                  v-model="item.code"
                >
                  <el-option
                    v-for="(item1, idx) in list"
                    :key="idx"
                    :label="item1.name"
                    :value="item1.code"
                  >
                  </el-option>
                </el-select>
                <el-input v-model="item.percentage" @input="changePercentage" placeholder="請(qǐng)輸入" class="benchmarkInputWidth"></el-input>
                <span style="padding-left: 2px;">%</span>
                <i v-if="index !== 0" style="font-size: 18px;cursor: pointer;padding: 0 0 0 10px;color: #F56C6C;" @click="deleteIndex(index)" class="el-icon-remove-outline"></i>
              </div>
              <div v-if="benchmarkRule" style="color: #F56C6C;font-size: 12px;margin-top: -17px">請(qǐng)選擇名稱</div>
              <el-button @click="addIndex" size="mini" type="primary" icon="el-icon-plus">添加</el-button>
            </el-form-item>
          </el-col>
          <el-col :span="12">
          </el-col>
        </el-row>
      </el-form>
      <div style="text-align: right;margin-top: 20px;">
        <el-button size="mini" @click="onClose()">取 消</el-button>
        <el-button
          size="mini"
          type="primary"
          @click="onConfirm()"
          >提 交</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>
data() {
    return {
      dialogVisible: false,
      combinationInfo: {
        benchMarks: [
          {
            code: '',
            name: '',
            percentage: '',
          }
        ]
      },
      rules: {
        benchMarks: [{ required: true }],
      },
      benchmarkRule: false,
      benchmarkTotal: 0,
      list: [
        {
          name: 'aaa',
          code: '111',
        },
        {
          name: 'bbb',
          code: '222',
        },
        {
          name: 'ccc',
          code: '333',
        },
      ],
    }
  },
methods: {
 // 添加
    addIndex () {
      this.combinationInfo.benchMarks.push({
        code: '',
        percentage: '',
      })
    },
    // 刪除
    deleteIndex (index) {
      this.combinationInfo.benchMarks.splice(index,1)
      this.changePercentage()
    },
    changeBenchmark (val) {
      if (this.combinationInfo.benchMarks.length && this.combinationInfo.benchMarks.length > 1) {
        if (!this.isRepeat(this.combinationInfo.benchMarks,'code')) {
          this.$message.warning('所選名稱不能重復(fù)!')
          return
        }
      }
    },
     // 判斷數(shù)組中是否有重復(fù)數(shù)據(jù)(true 不存在;false 存在重復(fù))
    isRepeat(arr, key) {
      var obj = {};
      for (let i = 0; i < arr.length; i ++) {
          if (obj[arr[i][key]]) {
              return false;    // 存在
          } else {
            obj[arr[i][key]] = arr[i];
          }
      }
      return true;
    },
    // 名稱值變化時(shí)
    changePercentage (val) {
      this.benchmarkTotal = 0
      if (this.combinationInfo.benchMarks.length && this.combinationInfo.benchMarks.length > 0) {
        for(let i = 0; i < this.combinationInfo.benchMarks.length; i++) {
          if (this.combinationInfo.benchMarks[i].percentage === '') {
            break
          }
          this.benchmarkTotal+=parseFloat(this.combinationInfo.benchMarks[i].percentage)
        }
      }
    },
    // 提交
    onConfirm() {
      if (this.combinationInfo.benchMarks) {
          for(let i = 0; i< this.combinationInfo.benchMarks.length; i++) {
            if (this.combinationInfo.benchMarks[i].code) {
              this.benchmarkRule = false
            } else {
              this.benchmarkRule = true
              return
            }
          }
        }
        if (this.benchmarkTotal !== 100) {
          this.$message.warning('名稱比例之和需為100%!')
          return
         }
     },
     // 取消
    onClose() {
      this.benchmarkRule = false
      this.dialogVisible = false
    },
},

展示效果圖:

在這里插入圖片描述

到此這篇關(guān)于vue elementui 動(dòng)態(tài)追加下拉框、輸入框的文章就介紹到這了,更多相關(guān)vue elementui 追加下拉框內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Vue3中關(guān)于ref和reactive的區(qū)別分析

    Vue3中關(guān)于ref和reactive的區(qū)別分析

    這篇文章主要介紹了vue3關(guān)于ref和reactive的區(qū)別分析,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧
    2023-06-06
  • Vue3使用組合式API實(shí)現(xiàn)代碼的邏輯復(fù)用

    Vue3使用組合式API實(shí)現(xiàn)代碼的邏輯復(fù)用

    在 Vue 3 的生態(tài)中,組合式 API(Composition API)引入了全新的方式來(lái)構(gòu)建組件,使得邏輯復(fù)用變得更加簡(jiǎn)單和靈活,在傳統(tǒng)的選項(xiàng)API中,邏輯復(fù)用通常依賴于混入和高階組件,本文將通過(guò)示例,帶你了解如何在 Vue 3 中使用組合式 API 來(lái)實(shí)現(xiàn)代碼的邏輯復(fù)用
    2025-01-01
  • Vue中實(shí)現(xiàn)深度監(jiān)聽(tīng)的方法小結(jié)

    Vue中實(shí)現(xiàn)深度監(jiān)聽(tīng)的方法小結(jié)

    在Vue中,深度監(jiān)聽(tīng)是一種非常常見(jiàn)且重要的功能,它可以讓我們監(jiān)聽(tīng)對(duì)象內(nèi)部的所有屬性,并對(duì)這些屬性的變化做出相應(yīng)的處理,在本篇博客中,我將為大家介紹Vue中如何實(shí)現(xiàn)深度監(jiān)聽(tīng)的方法,需要的朋友可以參考下
    2024-09-09
  • VUE3+TS遞歸組件實(shí)現(xiàn)TreeList設(shè)計(jì)實(shí)例詳解

    VUE3+TS遞歸組件實(shí)現(xiàn)TreeList設(shè)計(jì)實(shí)例詳解

    這篇文章主要為大家介紹了VUE3+TS遞歸組件實(shí)現(xiàn)TreeList設(shè)計(jì)實(shí)例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-09-09
  • el-form-item中表單項(xiàng)label和表單項(xiàng)內(nèi)容換行實(shí)現(xiàn)方法

    el-form-item中表單項(xiàng)label和表單項(xiàng)內(nèi)容換行實(shí)現(xiàn)方法

    這篇文章主要給大家介紹了el-form-item中表單項(xiàng)label和表單項(xiàng)內(nèi)容換行實(shí)現(xiàn)的相關(guān)資料,每個(gè)表單el-form由多個(gè)表單域el-form-item組成,需要的朋友可以參考下
    2023-09-09
  • vue自動(dòng)化表單實(shí)例分析

    vue自動(dòng)化表單實(shí)例分析

    本篇文章通過(guò)實(shí)例給大家分享了vue自動(dòng)化表單的操作方法以及相關(guān)的代碼做了描述,有興趣的朋友可以跟著學(xué)習(xí)下。
    2018-05-05
  • VUE的數(shù)據(jù)代理與事件詳解

    VUE的數(shù)據(jù)代理與事件詳解

    這篇文章主要為大家介紹了VUE的數(shù)據(jù)代理與事件,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來(lái)幫助
    2021-11-11
  • 源碼分析Vue.js的監(jiān)聽(tīng)實(shí)現(xiàn)教程

    源碼分析Vue.js的監(jiān)聽(tīng)實(shí)現(xiàn)教程

    這篇文章主要通過(guò)源碼分析介紹了Vue.js的監(jiān)聽(tīng)實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),相信對(duì)大家具有一定的參考價(jià)值,需要的朋友們下面來(lái)一起看看吧。
    2017-04-04
  • Vue中request.js封裝及調(diào)用示例詳解

    Vue中request.js封裝及調(diào)用示例詳解

    這篇文章主要為大家介紹了Vue中request.js封裝及調(diào)用示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-09-09
  • vue2利用html2canvas+jspdf動(dòng)態(tài)生成多頁(yè)P(yáng)DF方式

    vue2利用html2canvas+jspdf動(dòng)態(tài)生成多頁(yè)P(yáng)DF方式

    利用vue2結(jié)合html2canvas和jspdf,可以實(shí)現(xiàn)前端頁(yè)面內(nèi)容導(dǎo)出為PDF的功能,首先需要安裝相關(guān)依賴,使用html2canvas將指定div內(nèi)容捕捉為圖像,再通過(guò)jspdf將圖像轉(zhuǎn)換為PDF
    2024-09-09

最新評(píng)論