1. 程式人生 > >vue.js實現頁面倒計時跳轉功能

vue.js實現頁面倒計時跳轉功能

his 首頁 turn return () data col world mit

需求分析:

頁面倒計時5秒後進入系統主頁,數字需要實時更新!

<template>
  <div class="">
    <h1>歡迎來到Vue.js項目首頁</h1>
    <h2>你將在<span style="color:red">{{time}}</span>秒後進入系統</h2>
  </div>
</template>

<script>
export default {
  name: ‘HelloWorld‘,
  data () {
    return
{ time:0, } }, methods:{ countDown(){ let THIS=this; THIS.time--; } }, mounted(){ let THIS=this; THIS.time=5; setInterval(THIS.countDown,1000); }, watch:{ ‘time‘:function(newVal,oldVal){ if(newVal==0){ this.$router.push(‘/index‘); } } } }
</script> <!-- Add "scoped" attribute to limit CSS to this component only --> <style scoped> </style>

vue.js實現頁面倒計時跳轉功能