點選新增按鈕增加一行input 點選減號 刪除當前行
阿新 • • 發佈:2021-12-14
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); },