我正在更新发送到 Vue 中的“锻炼”组件的“锻炼”道具。在子组件中,我发出一个函数来增加你所在的集合。该函数在父组件中触发(我得到了 console.logs()),但子组件没有重新渲染。
家长:
<ExerciseListItem
v-for="(exercise) in exercises"
v-on:completeSet="completeSet"
v-on:selectExercise="selectExercise"
v-bind:exercise.sync="exercise"
v-bind:isActiveExercise="exercise.slug === activeExerciseSlug"
v-bind:key="exercise.slug"
/>
方法:
methods: {
completeSet: function(slug) {
console.log("complete-set", slug);
const exercise = this.getExerciseBySlug(slug);
exercise.completedSets++;
if (exercise.completedSets === exercise.totalSets) {
this.completeExercise(slug);
}
},
completeExercise: function(slug) {
this.getExerciseBySlug(slug).isComplete = true;
console.log("COMPLETE-exercise", slug);
},
getExerciseBySlug: function(slug) {
return this.exercises.find(exercise => exercise.slug === slug);
},
selectExercise: function(selectedSlug) {
this.activeExerciseSlug = selectedSlug;
}
},
子模板
<li
v-bind:class="{ 'white-box': true, complete: exercise.isComplete }"
v-on:click="exercise.totalSets > 1 ? $emit('selectExercise', exercise.slug) : $emit('completeSet', exercise.slug)"
>
帮助表示赞赏