当前位置:   article > 正文

element ui 新增动态表单_elementui动态添加表单

elementui动态添加表单

在这里插入图片描述
以下代码:

<div v-for="(item, index) in addForm.domains" :key="index">
  <el-form-item
    label="联系人"
    :prop="'domains.' + index + '.contactss'"
    :rules="{
      required: true, message: '联系人不能为空', trigger: 'blur'
    }"
  >
    <el-input v-model="item.contactss" style="width:300px" />
  </el-form-item>
  <el-form-item
    label="试点名称"
    :prop="'domains.' + index + '.regionNames'"
    :rules="[
      {required: true, message: '试点名称不能为空', trigger: 'blur'}
    ]"
  >
    <el-input v-model="item.regionNames" style="width:300px" />
  </el-form-item>
  <el-form-item
    label="承试单位"
    :prop="'domains.' + index + '.undertakeOrgs'"
    :rules="[
      {required: true, message: '承试单位不能为空', trigger: 'blur'}
    ]"
  >
    <el-input v-model="item.undertakeOrgs" style="width:300px" />
  </el-form-item>
  <el-form-item
    label="试验情况"
    :prop="'domains.' + index + '.remarks'"
    :rules="[
      {required: true, message: '试验情况不能为空', trigger: 'blur'}
    ]"
  >
    <el-input v-model="item.remarks" style="width:300px" />
  </el-form-item>
  <el-form-item>
    <i class="el-icon-delete" @click="deleteItem(item, index)" />
  </el-form-item>
</div>
<div class="text-center">
  <el-button @click="addItem">新增试点</el-button>
  <el-button class="button" @click="handleAddcancel()">取消</el-button>
  <el-button class="button" type="primary" @click="handleAddsave()">保存</el-button>
</div>

domains: [{
  contactss: '',
  regionNames: '',
  undertakeOrgs: '',
  remarks: ''
}],

addItem() {
  this.addForm.domains.push({
    contactss: '',
    regionNames: '',
    undertakeOrgs: '',
    remarks: ''
  })
},
deleteItem(item, index) {
  if (this.addForm.domains.length !== 1) {
    this.addForm.domains.splice(index, 1)
  } else {
    Message({ message: '最少添加一个试点', type: 'warning', duration: 5 * 1000 })
  }
},
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/91286
推荐阅读