代码实现
<template>
{
{ count }}秒后返回网站首页 <br>
</template>
<script lang="ts"> import router from "/@/router"; import { onMounted, reactive, ref} from "vue"; export default { setup(): any { onMounted(() => { countdown() //页面一加载成功就执行 }) let timer = null let count: number = ref(10) //倒计时 function countdown() { timer = setInterval(() => { count.value = count.value-1 if (count.value <= 0) { clearInterval(timer); timer = null; //跳转的页面写在此处 router.push({ path: "/"}); // 强制切换当前路由 path } }, 1000) } return { count } } } </script>
还没有评论,来说两句吧...