반응형
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의mapFields
helper method를 사용하면 getter 및 setter를 동적으로 설정할 수 있습니다.
언급URL : https://stackoverflow.com/questions/52401389/using-get-set-computed-property-with-mapstate-mapmutation-in-vuex
반응형
'programing' 카테고리의 다른 글
Vue CLI 버전을 확인하려면 어떻게 해야 합니까? (0) | 2022.07.29 |
---|---|
JRebel의 대체 수단 재배포 (0) | 2022.07.29 |
클래스 메서드에서 Vue 변수에 액세스하는 올바른 방법 (0) | 2022.07.29 |
vuex에 저장된 값을 기반으로 vuejs 페이지의 경로를 변경하려면 어떻게 해야 합니까? (0) | 2022.07.29 |
printf()를 사용하여 출력할 문자열의 글자 수를 지정하는 방법이 있습니까? (0) | 2022.07.29 |