vue elementui 动态追加下拉框、输入框

ops/2024/9/25 23:23:42/

elementui__0">vue elementui 动态追加下拉框、输入框

上代码:

<template><div><el-dialogappend-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%(当前<span>{{benchmarkTotal}}</span><span></span>%)</div><div v-for="(item,index) in combinationInfo.benchMarks" :key="index"><el-selectstyle="margin-bottom: 10px;"clearablefilterablecollapse-tagsplaceholder="请选择"class="benchmarkSelectWidth"@change="changeBenchmark"v-model="item.code"><el-optionv-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="请输入" 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">请选择名称</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-buttonsize="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('所选名称不能重复!')return}}},// 判断数组中是否有重复数据(true 不存在;false 存在重复)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;},// 名称值变化时changePercentage (val) {this.benchmarkTotal = 0if (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 = truereturn}}}if (this.benchmarkTotal !== 100) {this.$message.warning('名称比例之和需为100%!')return}},// 取消onClose() {this.benchmarkRule = falsethis.dialogVisible = false},
},

展示效果图:
在这里插入图片描述


http://www.ppmy.cn/ops/18564.html

相关文章

python 使用flask_httpauth和pyjwt实现登录权限控制

最近需要用到&#xff0c;学习了一下记录 首先安装依赖 pip install Flask-HTTPAuth pyjwt passlib Welcome to Flask-HTTPAuth’s documentation! — Flask-HTTPAuth documentation Welcome to PyJWT — PyJWT 2.8.0 documentation Passlib 1.7.4 documentation — Passl…

设计不外流,保护创意的同时锁住图纸安全!

在设计行业中&#xff0c;图纸和创意文稿的安全至关重要&#xff0c;因为它们体现了企业的创新能力和核心竞争力。华企盾DSC数据防泄密系统提供了一系列功能&#xff0c;可以有效地保护这些珍贵的设计和文档不被外泄。以下是如何利用华企盾DSC系统保障设计图纸安全的关键措施&a…

OpenHarmony语言基础类库【@ohos.util.HashSet (非线性容器HashSet)】

HashSet基于[HashMap]实现。在HashSet中&#xff0c;只对value对象进行处理。 HashSet和[TreeSet]相比&#xff0c;HashSet中的数据无序存放&#xff0c;即存放元素的顺序和取出的顺序不一致&#xff0c;而TreeSet是有序存放。它们集合中的元素都不允许重复&#xff0c;但Hash…

简明了解常规SpringBoot项目结构

一个典型的 Java Spring Boot 项目的结构通常遵循一定的约定&#xff0c;以便于组织代码和资源。 以下是一个基本的项目结构示例&#xff0c;它包含了常见的目录和文件&#xff1a; my-spring-boot-project/ │ ├── src/ │ ├── main/ │ │ ├── java/ │ │…

阿里云企业邮箱API的使用方法?调用限制?

阿里云企业邮箱API性能如何优化&#xff1f;配置邮箱API的优势&#xff1f; 阿里云企业邮箱以其稳定、高效和安全的特点&#xff0c;受到了众多企业的青睐。而阿里云企业邮箱API的开放&#xff0c;更是为企业提供了更加灵活、便捷的管理和操作方式。下面&#xff0c;我AokSend…

【前端技术】CSS基本语法(二)

一、 flex布局 flex布局称之为弹性布局给父元素设置display:flex&#xff0c;子元素可以自动挤压或拉伸内容&#xff0c;主轴方向默认为水平方向&#xff08;从左至右&#xff09; <!DOCTYPE html> <html lang"en"><head><meta charset"…

快速上手canvas

什么是Canvase Canvas 是 HTML5 中的一个重要特性&#xff0c;它允许你使用 JavaScript 在网页上动态绘制图形。Canvas 通过 JavaScript 来控制&#xff0c;在 HTML 页面中创建一个画布元素 <canvas>&#xff0c;然后使用 JavaScript 中的 Canvas API 来进行绘制。 用法…

PyTorch的基本概念及使用场景

PyTorch是一个用于构建动态计算图的开源机器学习框架。它由Facebook的人工智能研究团队开发&#xff0c;并于2017年发布。PyTorch提供了丰富的工具和库&#xff0c;使用户能够轻松地构建和训练神经网络模型。 PyTorch的核心概念是张量&#xff08;tensor&#xff09;和自动求导…