点击添加按钮增加一行input 点击减号 删除当前行

html

        <div v-for="(item, i) in studentList">
          <el-form label-width="60px" :inline="true">
            <el-form-item label="名字:" prop="name">
              <el-input
                v-model="item.name"
                clearable
                placeholder="名字"
              ></el-input>
            </el-form-item>
            <el-button
              circle
              icon="el-icon-plus"
              @click="addList()"
               v-if="i == 0"
    ></el-button>
            <el-button
              circle
              icon="el-icon-minus"
              @click="subList(i)"
              v-if="i > 0"
            ></el-button>
          </el-form>
        </div>

 

 

字段定义

studentList: [{ name: "", value: "" }],

方法

    //
    addList() {
      this.studentList.push({ name: "", value: "" });
    },
    //
    subList(index) {
      this.studentList.splice(index, 1);
    },

 

posted @ 2021-12-14 11:03  想吃水煮麻辣鱼  阅读(224)  评论(0)    收藏  举报