Vue의 상태관리를 위해 Vuex를 사용한다.
import { createStore } from 'vuex'
const store = createStore({
state(){
return {
globalState : "This is GlobalState!!"
}
},
})
export default store
import store from './store.js'
app.use(store).mount('#app')
import { createStore } from 'vuex'
const store = createStore({
state(){
return {
globalState : "This is GlobalState!!"
}
},
mutations :{
stateChange(state){
state.globalState = "State Change !!"
}
},
})
export default store
<button @click="$store.commit('stateChange')">버튼</button>
import { createStore } from 'vuex'
const store = createStore({
state(){
return {
globalState : "This is GlobalState!!"
}
},
mutations :{
stateChange(state){
state.globalState = "State Change !!"
}
},
actions : {
getData(context){
axios.get('').then(()=>{
context.commit("stateChange")
})
}
}
})
export default store