Vue.js,发出从 child 到 parent 的多个参数
Vue.js, emit multiple parameters from child to parent
我正在尝试发出从 child 到 parents.What 的多个参数是最好的方法。
Child
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 );
},
Parent
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;
}
},
我正在尝试发出从 child 到 parents.What 的多个参数是最好的方法。
Child
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 );
},
Parent
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;
}
},