Skip to content

Commit 33b000f

Browse files
committed
Fix quiz time implementation
1 parent 7e8545a commit 33b000f

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

examples/quiz/Example.vue

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
ref="flowform"
2020
v-on:complete="onComplete"
2121
v-on:submit="onQuizSubmit"
22+
v-on:timer="onTimer"
2223
v-bind:questions="questions"
2324
v-bind:language="language"
2425
v-bind:standalone="true"
@@ -55,7 +56,7 @@
5556
v-html="language.formatString(language.pressEnter)">
5657
</a>
5758
</div>
58-
<p class="text-success" v-if="submitted && timerOn()">Your time: {{ formatTime(getTime()) }}</p>
59+
<p class="text-success" v-if="submitted && time">Your time: {{ formattedTime }}</p>
5960
<p class="text-success" v-if="submitted && score < 4">"You scored {{ score }} out of {{ total }}. There's a lot of room for improvement."</p>
6061
<p class="text-success" v-else-if="submitted && score < 7">"You scored {{ score }} out of {{ total }}. Not bad at all!"</p>
6162
<p class="text-success" v-else-if="submitted && score <= total">"You scored {{ score }} out of {{ total }}. Wow, that's impressive!"</p>
@@ -88,6 +89,8 @@
8889
completed: false,
8990
score: 0,
9091
total: 8,
92+
time: 0,
93+
formattedTime: 0,
9194
answers: {
9295
html_1: ['2', '3'],
9396
html_2: 'false',
@@ -340,17 +343,10 @@
340343
this.calculateScore()
341344
},
342345
343-
getTime() {
344-
return this.$refs.flowform.time
345-
},
346-
347-
timerOn() {
348-
return this.$refs.flowform.timer
349-
},
350-
351-
formatTime(seconds) {
352-
return this.$refs.flowform.formatTime(seconds)
353-
}
346+
onTimer(time, formattedTime) {
347+
this.time = formattedTime
348+
this.formattedTime = formattedTime
349+
}
354350
},
355351
}
356352
</script>

src/components/FlowForm.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,7 @@
566566
567567
incrementTime() {
568568
++this.time
569+
this.$emit('timer', this.time, this.formatTime(this.time))
569570
},
570571
571572
formatTime(seconds) {

0 commit comments

Comments
 (0)