Создать файл firebase.js
в папке plugins
import firebase from 'firebase'
import 'firebase/firestore' //if use firestore
if (!firebase.apps.length) {
firebase.initializeApp({
apiKey: "xxx",
authDomain: "xxx,
databaseURL: "xxx",
projectId: "xxx",
storageBucket: "xxx",
messagingSenderId: "xxx"
})
}
firebase.firestore().settings({ timestampsInSnapshots: true })
const db = firebase.firestore()
const storage = firebase.storage() //if use storage
export { storage, db }
В компоненте:
import { db } from '~/plugins/firebase.js'
data() {
return {
users: []
}
},
mounted() {
db.collection("users").get().then((querySnapshot) => {
this.users = querySnapshot.docs.map(doc =>
Object.assign({ id: doc.id }, doc.data())
)
})
}