Last active
March 13, 2018 00:45
-
-
Save destroytoday/2d0267868c3e7e883382d65c1f636761 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const state = { | |
now: new Date | |
} | |
const actions = { | |
start ({ commit }) { | |
setInterval(() => { | |
commit('updateTime') | |
}, 1000 * 60) | |
} | |
} | |
const mutations = { | |
updateTime (state) { | |
state.now = new Date | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for your write up about this at https://cushionapp.com/journal/reactive-time-with-vuejs. I was just about to try and implement something like this when I stumbled upon your article. I'm creating an app that uses time and date in multiple components and I was doing it like you did with
setInterval(() => this.now = new Date, 1000 * 60)
in multiple components. I was already using Vuex so your solution made sense as soon as I saw it.