我正在嘗試實體化 firebase 并從 firestore 的集合中獲取一些檔案。我似乎無法讓我的應用程式實體化 firebase/連接到 firestore。我已經閱讀了 firebase V9 的檔案,這應該是正確的方法嗎?任何幫助將不勝感激!我收到錯誤訊息“在‘firebase/firestore’中未找到匯出‘getFirestore’”,并且我嘗試匯入的所有其他函式(例如 getDocs 等)都出現類似錯誤
。db.js
import {
initializeApp
} from 'firebase/app';
import {
getFirestore
} from 'firebase/firestore';
// Your web app's Firebase configuration
const firebaseConfig = {
etc...
};
// Initialize firebase and then firestore of that instance
export const app = initializeApp(firebaseConfig);
export const db = getFirestore(app);
應用程式
<template>
<v-app>
<v-app-bar
app
color="primary"
dark
>
<h1 app color="accent" light>Hans Lite</h1>
</v-app-bar>
<v-main>
<addFormula />
</v-main>
</v-app>
</template>
<script>
import addFormula from './components/addFormula.vue'
export default {
name: 'App',
components: {
addFormula
},
data: () => ({
//
}),
};
</script>
<style scoped>
h1 {
font-family: 'Roboto Mono', monospace;
font: bold;
}
</style>
添加公式.vue
<template>
<v-container fluid>
<v-col cols="12" md="3">
<v-card outlined>
<v-card-title class="font-weight-bold">Add Formulas</v-card-title>
<v-select elevation="2"
class="ma-4"
:items="items"
label="Select Package"
@change="selectPackage"></v-select>
</v-card>
</v-col>
</v-container>
</template>
<script>
import { db } from "../firebase/db"
import { collection, getDocs } from "firebase/firestore"
export default {
data: () => ({
items: ['chicken', 'beef'],
package: null
}),
methods: {
async selectPackage(e) {
console.log("label: " e)
this.package = e
const querySnapshot = await getDocs(collection(db, this.package))
var allDocs = [];
querySnapshot.forEach(doc => {
allDocs.push(doc.data())
})
console.log(allDocs)
}
}
}
</script>
<style scoped>
h1 {
/* border: solid; */
}
</style>
uj5u.com熱心網友回復:
請檢查NPMJSFirebase上的可用版本。
您提到的版本不存在或無效。在 firebase 發行說明和庫版本串列中。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/370462.html
