Reset exercise answers and results in VocabLessonView before loading new lessons

- Added logic to clear previous exercise answers and results when loading a new lesson, ensuring accurate tracking of user responses.
- Simplified the handling of exercise answers and results by directly assigning values instead of using Vue's `$set` method, improving code readability.
This commit is contained in:
Torsten Schulz (local)
2026-01-19 16:08:39 +01:00
parent 4e5ddc8027
commit 305e137a1a

View File

@@ -129,6 +129,9 @@ export default {
methods: {
async loadLesson() {
this.loading = true;
// Setze Antworten und Ergebnisse zurück
this.exerciseAnswers = {};
this.exerciseResults = {};
try {
const res = await apiClient.get(`/api/vocab/lessons/${this.lessonId}`);
this.lesson = res.data;
@@ -154,11 +157,11 @@ export default {
const exerciseType = this.getExerciseType(exercise);
if (exerciseType === 'gap_fill') {
const gapCount = this.getGapCount(exercise);
this.$set(this.exerciseAnswers, exercise.id, new Array(gapCount).fill(''));
this.exerciseAnswers[exercise.id] = new Array(gapCount).fill('');
} else {
this.$set(this.exerciseAnswers, exercise.id, '');
this.exerciseAnswers[exercise.id] = '';
}
this.$set(this.exerciseResults, exercise.id, null);
this.exerciseResults[exercise.id] = null;
});
},
async loadGrammarExercises() {
@@ -259,7 +262,7 @@ export default {
}
const res = await apiClient.post(`/api/vocab/grammar-exercises/${exerciseId}/check`, { answer });
this.$set(this.exerciseResults, exerciseId, res.data);
this.exerciseResults[exerciseId] = res.data;
} catch (e) {
console.error('Fehler beim Prüfen der Antwort:', e);
alert(e.response?.data?.error || 'Fehler beim Prüfen der Antwort');