问题描述
我正在尝试从孩子向父母发出多个参数。最好的方法是什么。
儿童
getUpdated(value,type) {
if (type === 'students') {
this.students = value.map(val => val.id);
}
if (type === 'programs') {
this.programs = value.map(val => val.code);
}
this.$emit('selectedOptions',students:this.students,programs:this.programs );
},
父母
onSelectedOption(students,programs) {
if (students !== undefined || students.length > 1) {
this.students = students;
}
if (programs !== undefined || programs.length > 1) {
this.programs = programs;
}
},
解决方法
发出具有多个属性的对象:
this.$emit('selectedOptions',{
students: this.students,programs: this.programs
});
在父级中:
onSelectedOption(options) {
if (options.students && options.students.length) {
this.students = options.students;
}
if (options.programs && options.programs.length) {
this.programs = options.programs;
}
},