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