반응형
Nuxt 가져오기 내에서 이름이 지정된 경우에는 Vuex 작업이 작동하지 않음
저는 저만의 작은 프로젝트를 만들고 있습니다.nuxt fetch 메서드 내의 메인스토어(index.js)에서 스테이트에 액세스하려고 하면 모두 정상적으로 동작하지만 namesched(store/photos.js) 스토어에서 액세스하려고 하면 동작하지 않습니다.여기 제 코드가 있습니다.
store/index.js (작업)
export const state = () => ({
fetchedData: []
})
export const mutations = {
setData: (state, data) => {
state.fetchedData = data;
}
}
export const actions = {
async get(vuexContext) {
const requestedData = await this.$axios.get("https://jsonplaceholder.typicode.com/users");
vuexContext.commit('setData', requestedData.data);
},
}
내 컴포넌트:
<script>
import { mapState, mapActions } from 'vuex'
export default {
async fetch({ error,store })
{
try {
await store.dispatch('get');
} catch (error) {
console.log(error);
}
},
computed: {
...mapState(['fetchedData'])
}
};
</script>
store/photos.js (동작하지 않음)
export const state = () => ({
list: []
});
export const mutations = {
setPhotos(state, data) {
state.list = data;
}
};
export const actions = {
async getPhotos(vuexContext, context) {
const requestedData = await this.$axios.get(
"https://jsonplaceholder.typicode.com/photos"
);
vuexContext.commit("setPhotos", requestedData.data);
}
};
같은 컴포넌트지만 수정됨
<script>
import { mapState, mapActions } from 'vuex'
export default {
async fetch({ error,store })
{
try {
await store.dispatch('photos/getPhotos');
} catch (error) {
console.log(error);
}
},
computed: {
...mapState({
list : 'photos/list'
})
}
};
</script>
잘 부탁드립니다.
namespaced: true,
이것을 index.js 파일에 추가할 수 있습니다.이게 먹히길 바라.
참조 링크:이거 드셔보세요
언급URL : https://stackoverflow.com/questions/65462552/vuex-action-not-works-with-namespaced-inside-nuxt-fetch
반응형
'itsource' 카테고리의 다른 글
C의 정수에서 가장 높은 설정 비트(msb)를 찾는 가장 빠르고 효율적인 방법은 무엇입니까? (0) | 2022.08.19 |
---|---|
Java의 다양한 유형의 스레드 세이프 세트 (0) | 2022.08.19 |
스프링-MVC 컨트롤러에서 404를 트리거합니까? (0) | 2022.08.19 |
BS4 라디오 버튼 그룹에서 Vue v-model이 반응하지 않음 (0) | 2022.08.19 |
JVM 옵션 - XSS - 정확히 어떤 역할을 합니까? (0) | 2022.08.19 |