我就廢話不多說了,大家還是直接看代碼吧~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
<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的延時
1
2
3
4
5
|
clearTimeout( this .timer); //清除延遲執行 this .timer = setTimeout(()=>{ //設置延遲執行 console.log( 'ok' ); },1000); |
以上這篇vue實現幾秒后跳轉新頁面代碼就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持服務器之家。
原文鏈接:https://blog.csdn.net/qq_38881495/article/details/89416104