반응형
정의되지 않은 속성 'ref'를 읽을 수 없습니다.
Vue + Firebase + Vuefire로 간단한 웹 앱을 만들고 있는데 컴포넌트 내에서 Firebase DB 변수를 사용하려고 하면 "Uncatched TypeError: Cannot read property 'ref' of undefined"라는 메시지가 나타납니다.
in main.js
Vue.use(VueFire)
const firebaseApp = Firebase.initializeApp({ //setting })
// Export the database for components to use.
export const db = firebaseApp.database()
그리고 내 컴포넌트에는
// in Recipes.vue
import {db} from '../main.js'
export default {
recipe: {
source: db.ref('recipes')
// Console says: "Uncaught TypeError: Cannot read property 'ref' of undefined"
}
}
저는 이 튜토리얼의 순서를 따랐습니다.https://alligator.io/vuejs/vuefire-firebase/
이 코드db.ref('recipes')
main.js 내에서 사용하면 동작하지만 컴포넌트 내에서 Import하면 동작하지 않습니다.
문제는 내 Firebase 코드(db 변수 포함)가 내부에 있다는 것이었다.main.js
자기 부품 안에 있어야만 했어요작성했습니다.firebase.js
파일:
import Firebase from 'firebase'
const firebaseApp = Firebase.initializeApp({
# configuration
})
// Export the database for components to use.
export const db = firebaseApp.database()
그런 다음 컴포넌트에서 데이터베이스 변수를 Import하기만 하면 됩니다.
import {db} from '../firebase'
왜 안에서는 안 되지?main.js
글쎄요, 좀 더 박식한 사람이 대답할 수 있을 거예요.
.ref
파이어베이스 함수이므로 Import해야 합니다.해 보세요.
import Firebase from 'firebase'
또는
import * from 'firebase'
언급URL : https://stackoverflow.com/questions/47253938/cannot-read-property-ref-of-undefined
반응형
'programing' 카테고리의 다른 글
메이븐을 사용하여 단일 테스트 방법 실행 (0) | 2022.08.10 |
---|---|
커스텀 CPU용 C 컴파일러를 작성하는 방법 (0) | 2022.08.10 |
계산된 Ajax가 있는 Vuex 작업이 업데이트되지 않음 (0) | 2022.08.10 |
Vuex 변환 업데이트 상태, 계산된 속성이 마크업에 업데이트를 반영하지 않음 (0) | 2022.08.10 |
"v-on:" 지시문을 사용하여 구성 요소에 이벤트 수신기 추가 - VueJS. (0) | 2022.08.10 |