programing

vue.js / Vue getter not defined 오류

randomtip 2022. 10. 2. 11:23
반응형

vue.js / Vue getter not defined 오류

앱에서 오류가 발생하였습니다.vue 컴포넌트, getter: 로그

<li id="shoppinglists" v-if="!logged">...

ERROR LOG: '[Vue warn]: Property or method "logged" is not defined on the instance but referenced during render. 
Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. 

정의된 다른 getter: currentUserId에서 오류가 발생하지 않기 때문에 왜 정의되지 않음으로 표시되는지 이해할 수 없습니다.

<li v-else id="shoppinglists"><router-link :to="{ name: 'ShoppingLists', params: { id: currentUserId } }" >Shopping Lists</router-link></li>

보테는 계산 소품으로 정의됩니다.

<script>
import store from '@/vuex/store'
import { mapGetters } from 'vuex'

export default {
  name: 'app',
  computed: {
    ...mapGetters([
      { currentUserId: 'getCurrentUserId' },
      { logged: 'getCurrentUserStatus' }
    ])
  },
  store
}
</script>

그리고 나의 vex/getters.displaces는 다음과 같습니다.

vuex/getters.displacy

export default {
  getCurrentUserStatus: state => state.logged,
  getCurrentUserId: state => state.currentUserId,
  ...
}

그리고 저희 가게는

vuex/store.module

import Vue from 'vue'
import Vuex from 'vuex'
import getters from './getters'
...

Vue.use(Vuex)

const state = {
  logged: false,
  currentUserId: '',
  ...
}

export default new Vuex.Store({
  state,
  getters,
   ...
})

오브젝트를 전달하다...mapGettersgetters를 다른 이름으로 사용하고 싶은 경우

구문은 다음과 같습니다.

...mapGetters({
      currentUserId: 'getCurrentUserId',
      logged: 'getCurrentUserStatus' 
 })

언급URL : https://stackoverflow.com/questions/46884463/vue-js-vue-getter-not-defined-error

반응형