programing

Vue mapActions 구성 방법

yoursource 2022. 8. 9. 21:53
반응형

Vue mapActions 구성 방법

vue-cli 스토어

mapActions ('일부/네스트/모듈', 'getCountry', 'getCurrency'),

여기에 이미지 설명 입력

Vue 구성 요소에서 mapActions 경로를 설정하는 방법

mapActions컴포넌트의methods소유물.

// my-component.vue
import { mapActions } from 'vuex'

export default {
    ...
    methods: {
        ...mapActions('namespaced/module', [
            'myAction',
            'myOtherAction'
        ])
    }
}

네임스페이스는 모듈의 파일명으로 판별할 수 있습니다.예를 들어, 파일이 지정되면 -moduleA.js- getters, modiate, actions는 다음과 같이 명명됩니다.moduleA/someGetter,moduleA/someAction,moduleA/someMutation.

...mapActions('moduleA', [
    'someAction',
    'anotherAction'
])

모듈이 등록되면 모듈이 등록된 경로에 따라 모든 게터, 동작 및 돌연변이가 자동으로 이름 지정됩니다.

또 다른 방법은,registerModulemethod: 동적 런타임 등록을 허용합니다.

// register a module `myModule`
store.registerModule('myModule', {
  // ...
})

// register a nested module `nested/myModule`
store.registerModule(['nested', 'myModule'], {
  // ...
})

Vuex Docs - 네임스페이스

Vuex Docs - 다이내믹모듈 등록

언급URL : https://stackoverflow.com/questions/49548718/how-to-configure-vue-mapactions

반응형