1. 程式人生 > 其它 >點選新增按鈕增加一行input 點選減號 刪除當前行

點選新增按鈕增加一行input 點選減號 刪除當前行

html

        <div v-for="(item, i) in studentList">
          <el-form :label-position="left" label-width="60px" :inline="true">
            <el-form-item label="名字:" prop="name">
              <el-input
                v-model="studentList[i].name"
                clearable
                placeholder
="名字" ></el-input> </el-form-item> <el-button circle icon="el-icon-plus" @click="addList()" ></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); },