开启倒计时,直接保存到vuex中,且存储到本地持久化
// state.js
const runTime = localStorage.getItem('time');
paymentRunTime:runTime
// mutations.js
TimeReduction(state) {
this.timerId = setInterval(() => {
if (state.paymentRunTime === 0) {
state.paymentRunTime = 60;
return clearInterval(this.timerId)
}
state.paymentRunTime -= 1;
localStorage.setItem('time',state.paymentRunTime)
},1000);
},
在需要用到的页面钩子函数调用方法, created(){ this.$store.commit(TimeReduction) }
知识点扩展:
倒计时实例代码:
获取验证码
{{showtime}}
以上就是vue倒计时刷新页面不会从头开始的解决方法的详细内容,更多关于vue倒计时刷新页面不会从头开始的资料请关注考高分网其它相关文章!



