store/index.js
CMD> npm i vuex@next --save
import { createStore } from "vuex";
어떤 컴포넌트에서 바꿀수 있는 변수
state : {
counter : 20,
},
다른 컴포넌트에서도 methods
의 역할을 함
getCounter(state){
return state.counter;
},
동기 - 순차적으로 실행 {단점: 효율이 떨어짐}
mutations : {
setCounter : (state, value) => {
state.counter = value;
},
setCounter1 (state, value) {
state.counter = value + 100;
}
},
비동기 - 시작순서는 순차적, 끝나는 순서는 달라짐.
actions : {
actionCounter(context, payload){
const value = payload.counter;
// 위에 생성되어있는 mutation의 setCounter를 호출함
// 끝나는 지점만 다르게!
context.commit('setCounter', value);
}
},