我就废话不多说了,大家还是直接看代码吧~
<template> <div @click="clickJump()">提交</div> </template> <script> export default { data(){ return { count:"",//倒计时 } } }, mounted(){ }, methods: { //几秒后进入跳转页面 clickJump(){ const timejump = 1; if(!this.timer){ this.count = timejump ; this.show = false; this.timer = setInterval(()=>{ if(this.count > 0 && this.count <= timejump ){ this.count--; }else{ this.show = true; clearInterval(this.timer); this.timer = null; //跳转的页面写在此处 this.$router.push({path: '/address'}); } },100) } }, } </script>
补充知识:vue设置延时
一定要创建一个timer,然后调用延时之前先清除timer的延时
clearTimeout(this.timer); //清除延迟执行 this.timer = setTimeout(()=>{ //设置延迟执行 console.log('ok'); },1000);
以上这篇vue实现几秒后跳转新页面代码就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持自学编程网。
- 本文固定链接: https://zxbcw.cn/post/195232/
- 转载请注明:必须在正文中标注并保留原文链接
- QQ群: PHP高手阵营官方总群(344148542)
- QQ群: Yii2.0开发(304864863)