開啟倒計時,直接保存到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) }
效果,頁面與本地存儲始終保持一致,即使刷新頁面也不會重新計時

