2

我正在尝试从孩子向父母发出多个参数。最好的方法是什么。

孩子

 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;
  }
},
4

1 回答 1

4

发出具有多个属性的对象:

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;
  }
},
于 2021-01-12T14:45:00.247 回答