vue dom的操作其实就是对数据的操作,通过数据进行的渲染达到想要的追加
定义一个变量teacherIdArray :[],teacherdataarray:[]
<el-form-item label="教师" prop="id">
<div v-for="(teacherdata1, index) in teacherdataarray" >
<el-select v-model="form.teacherIdArray[index]" placeholder="请选择教师">
<el-option
v-for="(item,key, index) in teacherdata1"
v-bind:key="item.teacher_id"
:label="item.teacher_name"
:value="item.teacher_id"
></el-option>
</el-select>
<img src="static/img/add-p.png" class="class_add" alt="" @click="addapplyteacherdata">
<img src="static/img/min.png" class="class_add" alt="" @click="deleteItemteacherdata(index)">
</div>
</el-form-item>
//追加教师
addapplyteacherdata() {
this.teacherdataarray.push(this.teacherdata);
},
deleteItemteacherdata(index) {
this.teacherdataarray.splice(index, 1);
},
//获取教师列表
getteacherdataurl() {
this.$axios.get(this.teacherdataurl, {}).then(res => {
// console.log("/获取教师列表"+JSON.stringify(res))
this.teacherdata = res.data.data;
this.teacherdataarray.push(res.data.data);
});
},
在函数中就可以拿到想要的id数组
console.log("AAAA="+JSON.stringify(this.form.teacherIdArray))