Skip to content

Instantly share code, notes, and snippets.

@M1cr0M1nd
Created May 29, 2019 10:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save M1cr0M1nd/932e11b680726c089f41b234bbd3b844 to your computer and use it in GitHub Desktop.
Save M1cr0M1nd/932e11b680726c089f41b234bbd3b844 to your computer and use it in GitHub Desktop.
Intro to the Vue State Manager - Vuex
const store = new Vuex.Store({
state: {
score: 0
},
mutations: {
SET_SCORE (state, value) {
state.score = value
}
},
actions: {
async setScore ({ commit }) {
let { data } = await Axios.post('http://scoresrus.com/getScoreApi')
if (data.status == 200) {
commit('SET_SCORE', data.data.score)
}
}
}
})
const ScoreDashboard = {
template: `<div>{{ score }}</div>`,
computed: {
score () {
return this.$store.state.score
}
},
mounted () {
this.$store.dispatch('setScore', 10)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment