Skip to content

Instantly share code, notes, and snippets.

@destroytoday
Last active March 13, 2018 00:45
Show Gist options
  • Save destroytoday/2d0267868c3e7e883382d65c1f636761 to your computer and use it in GitHub Desktop.
Save destroytoday/2d0267868c3e7e883382d65c1f636761 to your computer and use it in GitHub Desktop.
const state = {
now: new Date
}
const actions = {
start ({ commit }) {
setInterval(() => {
commit('updateTime')
}, 1000 * 60)
}
}
const mutations = {
updateTime (state) {
state.now = new Date
}
}
@kahunacoder
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment