-
-
Save M1cr0M1nd/932e11b680726c089f41b234bbd3b844 to your computer and use it in GitHub Desktop.
Intro to the Vue State Manager - Vuex
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 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