我已经实现了以下定义的简单自定义事件。但是,每当我将值发送回父级时,访问其属性都将导致未定义。我完全不知道为什么...
<!-- Parent Component function -->
onAddExercise(
workoutIndex: number,
workoutRoundIndex: number,
exercise: ExerciseModel
) {
console.log(exercise); outputs the whole object with values
console.log(exercise.id); undefined!
console.log(exercise.name); undefined!
}
/
<-- Render Child Component in Parent -->
<ExerciseSearch @onAddExercise="onAddExercise"
:workoutIndex="wIndex"
:workoutRoundIndex="wrIndex"
/>
/
<-- Child Component function -->
async onSelectExercise(exerciseId: string) {
var response = await this.$apollo.query({
query: EXERCISE,
variables: {
id: exerciseId
}
});
let exercise = response.data as ExerciseModel
console.log(exercise); outputs the whole object with values
console.log(exercise.id); outputs the id
console.log(exercise.name); outputs the name
<!-- Emit to Parent with payload -->
this.$emit(
"onAddExercise",
this.workoutIndex,
this.workoutRoundIndex,
exercise
);
}
更新