반응형
네임스페이스가 다른 유사한 이름의 vue/vuex mapActions 메서드에 액세스하는 방법
이 정도면 충분합니다.
created() {
this['shared/getPosts']();
this['posts/getPosts']();
},
methods: {
...mapActions(['shared/getPosts', 'posts/getPosts']),
},
다만, 이하의 코드를 예상대로 동작시킬 수 있는 방법이 있는지 어떤지, 코멘트를 참조해 주세요.
created() {
this.getPosts(); // triggers last method
},
methods: {
...mapActions('shared', ['getPosts']), // how to trigger this?
...mapActions('posts', ['getPosts']), // this gets triggered.
},
이름만 그렇게 바꿔주세요.
created() {
// call the first method
this.getSharedPosts();
// or second
this.getPosts();
},
methods: {
...mapActions('shared', {
getSharedPosts: 'getPosts', // <-- call it as `this.getSharedPosts()` in component
}),
...mapActions('posts', {
getPosts: 'getPosts', // <-- call it as `this.getPosts()`
}),
},
자세한 내용은 이쪽
언급URL : https://stackoverflow.com/questions/55269463/how-to-access-vue-vuex-mapactions-methods-with-similar-name-while-has-different
반응형
'source' 카테고리의 다른 글
| 실행 가능한 . .을 빌드합니다. (0) | 2022.08.21 |
|---|---|
| 포인터는 C에서 참조에 의한 호출 방식으로 간주됩니까? (0) | 2022.08.21 |
| Vue 하위 구성 요소 속성이 작동하지 않음 (0) | 2022.08.21 |
| Enum이 인터페이스를 구현하는 이유는 무엇입니까? (0) | 2022.08.21 |
| gitlab-ci에서의 VueJS 앱 e2e 테스트 (0) | 2022.08.20 |