programing

Vuex Store getter 함수를 찾을 수 없습니다.

itsource 2022. 7. 27. 22:56
반응형

Vuex Store getter 함수를 찾을 수 없습니다.

다음은 vuex 스토어에 있는 내 getters입니다.

  const getters= {
    getUser: (state:any) =>  {return state.user}
  };

제 견해로는 다음과 같습니다.

<script lang="ts">
  ...
  import {createNamespacedHelpers} from 'vuex'
  const {mapMutations, mapGetters} = createNamespacedHelpers('user');

  export default Vue.extend({

    computed: {
      ...mapGetters([
        'getUser'
      ])
    },

    methods: {
      ...mapMutations([
        'change'
      ]),
      login() {
        this.change(email); //This is a function in the mutations. And this is working
        this.loggedin = this.getUser(); // Here it says error

      }
    }
  });

다음과 같은 에러가 표시됩니다.

TypeError: this.getUser is not a functionthis.change(email);하지만 변이 기능은 작동하고 있습니다.

computed속성 없음methods호출되지 않도록 하는 거죠동작은 마치setters그리고.getters

this.getUser는 계산 속성으로, 값 자체로서 동작합니다.당신은 그것을 다루려고 한다.method할 때()호출하도록 합니다.그건 불가능하죠. 왜냐하면 그건fn그래서 오류가 나타나는 거예요.

https://vuejs.org/v2/guide/computed.html#Computed-Caching-vs-Methods 를 참조해 주세요.

Vuex getters/states에 포함되다computedvue의 특성instances그들의 일 자체가 반환되는 것이기 때문에value.하지만mutations/actions안에 포함시키다methods하는 것이 본연의 임무인 재산perform조작 예 - 만들기async요구 및 갱신state

언급URL : https://stackoverflow.com/questions/59101916/vuex-store-getter-function-not-found

반응형