【发布时间】:2021-10-06 11:17:53
【问题描述】:
我正试图在倒计时后重定向到另一个网站。重定向有效,但倒计时仅减少一次。
例如: 我已将计数器设置为 5。但是当弹出窗口打开时,它显示为 4,并且不会进一步减少。
<p>Redirecting in {{ counter }}</p>
<script>
export default {
name: "modal",
data() {
return {
toggleModal: false,
counter: 5
}
},
methods: {
showModal() {
this.toggleModal = true;
this.countDown();
},
countDown() {
if(this.counter > 0) {
this.counter--;
setTimeout(() => {
window.location.href = 'https://www.google.com';
}, 5000);
}
},
}
};
</script>
【问题讨论】:
-
欢迎来到stackoverflow
-
setTimeout(() => { window.location.href = 'https://www.google.com'; }, this.counter * 1000);也许?
标签: javascript vue.js vuejs2 vue-component vuetify.js