programing

계산된 속성 내에서 getter를 호출하는 방법

kingscode 2022. 8. 11. 18:36
반응형

계산된 속성 내에서 getter를 호출하는 방법

의 모듈 모드를 사용하고 있습니다.store그리고 내 안에projects.js스토어 폴더 내에는 다음과 같은 것이 있습니다.

export const getters = {
   loadedProjects(state) {
       return state.loadedProjects;
   }
}

내 계산으로는 뭐라고 불러야 할까?난 그렇게 노력하고 있어.

computed: {
   loadedProjects() {
     return this.$store.getters.projects.loadedProjects;
   },
 }

하지만 다음 오류가 나타납니다.

Cannot read property ‘loadedProjects’ of undefined

같은 문제가 있었습니다.모듈 모드를 사용하고 있는 경우는, 다음과 같이 getter를 호출할 수 있습니다(고객의 경우). this.$store.getters['projects/loadedProjects'];

따라서 다음과 같이 컴퓨터를 변경해 보십시오.

computed: {
   loadedProjects() {
     return this.$store.getters['projects/loadedProjects'];
   },
 }

이렇게 불러야 합니다.

loadedProjects() {
    return this.$store.getters['projects/loadedProjects'];
}

$store.getters['moduleName/getterName']

언급URL : https://stackoverflow.com/questions/57791973/how-to-call-a-getter-inside-a-computed-properties

반응형