【发布时间】:2021-04-27 06:34:54
【问题描述】:
我使用 Vue 制作了一个在线测验应用程序,其中每个问题都有自己的持续时间。我正在使用 watcher 进行倒计时并将其显示在网页上。我面临的问题是每次我更新时间以匹配下一个问题的时间时,倒计时会更快结束。如何在不中断当前倒计时的情况下更新观察者中的时间限制?
watch: {
timerEnabled(value) {
if (value) {
setTimeout(() => {
this.timeLimit--;
}, 1000);
}
},
timeLimit: {
handler(value) {
if (value >= 0 && this.timerEnabled) {
setTimeout(() => {
this.timeLimit--;
}, 1000);
}
else{
// set the timer to the next question's time limit and move to the next question
}
}
}
}
【问题讨论】:
标签: javascript vue.js nuxt.js