Closed sunmingtao closed 4 years ago
Actions and mutations
Key points:
// component
export default {
methods: {
onInput (value) {
this.$store.dispatch('setValue', value)
}
}
}
// action
actions: {
setValue ({ commit }, value) {
commit('setValue', value)
}
}
// mutation
mutations: {
setValue (state, value) {
state.value = value
}
}
Command line
npm install --save vuex
Create store.js
main.js
App.vue