programing

매핑된 Vuex 함수는 함수가 아니지만 로드됩니다.

minecode 2022. 7. 3. 00:21
반응형

매핑된 Vuex 함수는 함수가 아니지만 로드됩니다.

마운트된 후크에서 매핑된 Vuex 작업을 호출하면 작업이 작동하지만 콘솔에 "TypeError: xxx is not function" 오류가 표시됩니다.

이 컴포넌트에 대한 스크립트 섹션은 다음과 같습니다.

<script>
import SideNav from '@/components/SideNav.vue'
import ActionBar from '@/components/ActionBar.vue'
import Summaries from '@/components/Summaries.vue'
import { mapState, mapActions } from 'vuex'

export default {
  components: { SideNav, ActionBar, Summaries },
  computed: {
    ...mapState(['dataLoading']),
    ...mapActions(['init'])
  }, 
  mounted() {
    this.init();
  }
}
</script>

액션을 다음과 같이 매핑해야 합니다.methods대신computed컴포넌트의 디스패치액션을 참조해 주세요.

computed: {
  ...mapState(['dataLoading'])
},
methods: {
  ...mapActions(['init'])
},
mounted() {
  this.init();
}

언급URL : https://stackoverflow.com/questions/54117875/mapped-vuex-function-is-not-a-function-but-still-loads

반응형