Vue倒计时3秒后返回首页Demo(推荐)
更新时间:2023年11月16日 14:32:35 作者:karshey
这篇文章主要介绍了Vue倒计时3秒后返回首页Demo,倒计时结束后要清除计时器,防止内存泄漏,本文通过示例代码给大家介绍的非常详细,需要的朋友参考下吧
Vue倒计时3秒后返回首页Demo

首页path:'/'
倒计时结束后要清除计时器,防止内存泄漏:
if (this.count === 0) {
clearInterval(this.timer);
}<!-- ErrorJump.vue -->
<template>
<h2>Error:找不到页面!</h2>
<h4>{{ count }}S后<RouterLink to="/">跳回首页</RouterLink></h4>
</template>
<script>
export default {
data() {
return {
count: 0,
timer: null,
};
},
mounted() {
this.count = 3;
this.timer = setInterval(() => {
this.count--;
if (this.count === 0) {
clearInterval(this.timer);
this.$router.push("/");
}
}, 1000);
},
};
</script>vue中倒计时3秒后跳转页面
<template>
<div id="home">
<div>{{ count }}s后将自动跳转到登录页!</div>
</div>
</template>
<script>
export default {
data(){
return {
count:"",//倒计时
}
}
},
created(){
this.threeGo()
},
methods: {
//3秒后进入跳转页面
threeGo(){
const TIME_COUNT = 3;
if(!this.timer){
this.count = TIME_COUNT;
this.show = false;
this.timer = setInterval(()=>{
if(this.count > 0 && this.count <= TIME_COUNT){
this.count--;
}else{
this.show = true;
clearInterval(this.timer);
this.timer = null;
//跳转的页面写在此处
this.$router.push({
path: ''
});
}
},1000)
}
},
}
</script>到此这篇关于Vue倒计时3秒后返回首页Demo的文章就介绍到这了,更多相关vue倒计时3秒返回首页内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
相关文章
Vue3 使用v-md-editor如何动态上传图片的方法实现
本文主要介绍了Vue3 使用v-md-editor如何动态上传图片,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧2022-08-08
Vue 3 响应式系统中ref 在 reactive 中的自动解包行为
Vue3中,ref与reactive配合使用时会自动解包,使代码更简洁,响应式系统更智能,替换ref会断开旧连接,浅层reactive/shallowRef不触发解包,但是需注意区分,下面通过示例给大家介绍Vue3响应式探秘:ref 在reactive中的自动解包行为解析,感兴趣的朋友一起看看吧2025-07-07


最新评论