programing

vuex에서 mapState, mapMutation과 함께 계산 속성 get/set 사용

itsource 2022. 7. 29. 23:32
반응형

vuex에서 mapState, mapMutation과 함께 계산 속성 get/set 사용

다음과 같은 Vuex 모듈을 사용하여 계산된 속성이 있습니다.main:

computed: {
  foo: {
    get(){
      return this.$store.state.main.foo;
    },
    set(value) {
      this.$store.commit("main/foo", value);
    }
  }
}

사용하고 싶다get/set패턴을 사용하고 싶기 때문에v-model="foo"말을 걸어야 하는 것$store직접적으로는 아주 장황한 표현입니다.좀 더 쉬운 방법은 없을까?mapState,mapMutation또는 심지어createNamespacedHelpers?

vuex-map-fields 모듈을 사용해 볼 것을 권장합니다.이 모듈에는 vuex-map-fields의mapFieldshelper method를 사용하면 getter 및 setter를 동적으로 설정할 수 있습니다.

언급URL : https://stackoverflow.com/questions/52401389/using-get-set-computed-property-with-mapstate-mapmutation-in-vuex

반응형