【Vue-Demo】Return to homepage after 3 seconds countdown

Please add image description
front pagepath:'/'

After the countdown ends, clear the timer to prevent memory leaks:

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>

Guess you like

Origin blog.csdn.net/karshey/article/details/134437263