【Vue-Demo】倒计时3秒后返回首页

【Vue-Demo】倒计时3秒后返回首页_第1张图片
首页path:'/'

倒计时结束后要清除计时器,防止内存泄漏:

if (this.count === 0) {
	clearInterval(this.timer);
}

<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>

你可能感兴趣的:(前端demo,vue.js,javascript,前端)