Commit fbcf17e2 authored by 张恒's avatar 张恒

添加倒计时器,10s刷新页面

parent d6e7fc58
...@@ -7,10 +7,10 @@ ...@@ -7,10 +7,10 @@
<span>星期三</span> <span>星期三</span>
</div> </div>
<div class="text_right"> <div class="text_right">
<span>刷新时间:10s</span> <span>刷新时间:{{ countDown }}s</span>
</div> </div>
</div> </div>
<router-view style="height: 90%"></router-view> <router-view style="height: 90%" v-if="isRouterAlive"></router-view>
</div> </div>
</template> </template>
...@@ -21,9 +21,38 @@ window.$ = window.jQuery = require('materialize-css/node_modules/jquery/dist/jqu ...@@ -21,9 +21,38 @@ window.$ = window.jQuery = require('materialize-css/node_modules/jquery/dist/jqu
require('materialize-css') require('materialize-css')
export default { export default {
name: 'app', name: 'app',
data() {
return {
countDown: 10,
isRouterAlive: true,
countDownTimer: null,
}
},
methods: { methods: {
goIndex() { goIndex() {
this.$router.push({path: '/'}) this.$router.push({path: '/'})
},
reload() {
this.isRouterAlive = false
this.$nextTick(function () {
this.isRouterAlive = true
})
}
},
mounted() {
// 倒计时器
this.countDownTimer = setInterval(() => {
this.countDown--
if (this.countDown <= 0) {
this.reload()
this.countDown = 10
}
}, 1000)
},
beforeDestroy() {
// 倒计时器
if (this.countDownTimer) {
clearInterval(this.countDownTimer)
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment