티스토리 뷰

프론트엔드/Vue.js

vuex

실전압축코딩 2022. 6. 1. 22:09

What is Vuex? | Vuex (vuejs.org)

 

What is Vuex? | Vuex

What is Vuex? Pinia is now the new default The official state management library for Vue has changed to Pinia. Pinia has almost the exact same or enhanced API as Vuex 5, described in Vuex 5 RFC. You could simply consider Pinia as Vuex 5 with a different na

vuex.vuejs.org

 

Vue.use(Vuex);

 

export default new Vuex.store({

           state: {

           }

})

 

...

 

state  -> 저장소

 

mutations  -> 함수안에서 state에 접근해 값을 수정함 ,,, this.$store.commit('원하는 함수 이름', 파라미터)

 

actions -> '비동기 작업' 후 state에 반영할때  ,,, this$.store.dispatch('action 이름' , 파라미터) 

 

getters -> computed와 비슷, 바로 계산 값을 가져옴 ,,, this.$store.getters.'vuex getters 이름'

 

map 헬퍼 -> vuex의 값을 알아서 computed에 mapping함 ,,, ...mapState([ 'a' , 'b' ])  / ({ replace : 'a' }) 가능

 

Vuex Modules -> 관련된 로직을 뺴내 모듈화 -> this.$store.모듈이름.

 export default new Vuex.store({

           state: {

 

           },

           module: {

                  module1,

                  module2,

            }

 })

 module에는 namespace 추가

 getters -> this.$store.getters['module이름/getters']

 disptch ->  this.$store.dispatch('module이름/getters',파라미터)

 commit->  this.$store.commit('module이름/getters',파라미터)

 ...mapState([ 'a' : state => state.모듈.a ])