当前位置:   article > 正文

vue+element 实现批量新增多行_vue怎么表单数据批量增加

vue怎么表单数据批量增加

实现如下批量新增在这里插入图片描述

  1. 样式
 <div v-for = "(item, index) in form.list" :key = "index">
     <el-form-item  label = "选项" 
           :rules = "{required:true, message:'请输入', trigger: ''change}"
           :prop = " 'list.' + index + '.name' ">
         <el-input type= 'test' v-model = "item.name"
                 placeholder = "请输入"  clearable>
         </el-input>
     </el-form-item>
     <el-form-item>
          <el-button v-if = "index+q = form.list.length"
            type = "primary"  icon = " el-icon-plus" @click = "addRow">
          </el-button>
         <el-button v-if = "index !== 0" type = "primary"
            icon = " el-icon-minus" @click = "delRow(item, index)">
         </el-button>
     </el-form-item>
 </div>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  1. 参数声明
 form: {
   list:[{id:'',name:''}]
   }
  • 1
  • 2
  • 3
  1. js方法
    // 新增一行
   addRow(){
      if(this.form.list){
         var index = this.form.list.length - 1;
         var lastItem = JSON.parse(JSON.stringify(this.form.list[index]))
         lastItem.id = ''
         lastItem.name = ''
         this.form,list.push(lastItem)
        }
   }
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

// 删除一行

  delRow(item, index){
      this.form.list.splice(index, 1)
   }
  • 1
  • 2
  • 3
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/91367
推荐阅读