Posted in Vue.js onDecember 17, 2020
参考elementUI官网以及网上的其他一些资料。话不多说,直接贴代码。
htmt部分:
<div id="app" style="width: 500px;"> <el-form :model="environmentForm" ref="environmentForm"> <el-row :gutter="24" v-for="(item, index) in environmentForm.items" :key="item.key"> <el-col :span="6"> <el-form-item :prop="'items.' + index + '.name'" :rules="{required: true, message: '名称不能为空', trigger: 'blur'}"> <el-input v-model="item.name"></el-input> </el-form-item> </el-col> <el-col :span="6"> <el-form-item :prop="'items.' + index + '.variable'" :rules="{required: true, message: '变量值不能为空', trigger: 'blur'}"> <el-input v-model="item.variable"></el-input> </el-form-item> </el-col> <el-col :span="3" v-if="environmentForm.items.length !== 1"> <el-button @click="removeEnvironmentForm(item)" class="el-icon-delete" size="mini" circle> </el-button> </el-col> <el-col :span="3"> <el-button @click="addEnvironmentForm" size="mini" class="el-icon-plus" circle></el-button> </el-col> </el-row> <el-form-item> <el-button type="primary" @click="submitForm('environmentForm')">提交</el-button> <el-button @click="resetForm('environmentForm')">重置</el-button> </el-form-item> </el-form> </div>
实现效果:单个时
多个时显示删除按钮
到此这篇关于vue+elementUI动态增加表单项并添加验证的代码详解的文章就介绍到这了,更多相关vue+elementUI增加表单项内容请搜索三水点靠木以前的文章或继续浏览下面的相关文章希望大家以后多多支持三水点靠木!
vue+elementUI动态增加表单项并添加验证的代码详解
- Author -
不吃肉的羊声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@