I am trying to redirect to another website after countdown. The redirect works, however the countdown decrease only one time.
For example: I have set the counter to 5. But when the pop up opens, its shows 4 and doesn't decrease further.
<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>