A
A
Andrew2019-10-31 09:12:20
firebase
Andrew, 2019-10-31 09:12:20

Wait for firestore to load and put in vuex?

Created a database, a collection.
How do I now use firestore "style" REST API? I connected vuefire, but it has a lot of its own magic under the hood.
I need to put all the records from the collection into vuex, plus wait for the load (show the loader). You also need to get records with the query parameters skip and limit (for pagination), sort by date, and get the number of all records in the collection with a quick query (ala count).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Likhomanov, 2019-10-31
@KraisLi

Remove the crutch (vuefire).
In main.js

import firebase from 'firebase/app'
import 'firebase/firestore'

firebase.initializeApp({
    apiKey: "****************",
    authDomain: "****************",
    databaseURL: "****************",
    projectId: "****************",
    storageBucket: "****************",
    messagingSenderId: "****************",
    appId: "****************",
    measurementId: "****************",
});
export const db = firebase.firestore();

VUE component:
import firebase from 'firebase/app';
import 'firebase/auth';
import {db} from '../main'

    export default {
        name: 'component-name',
        data() {
            return {
                loading: false
            }
        },
        methods: {
            fetchList() {
            this.loading = true;
            db.collection("collectionName").get()
                .then(function (querySnapshot) {
                    let list = {};
                    if (querySnapshot) {
                        querySnapshot.forEach(function (doc) {
                            // console.log(doc.id, " => ", doc.data());
                            list[doc.id] = doc.data();
                        });
                    }
                    console.log('Результат: ', list)
                })
                .catch(function (error) {
                    console.log("Error getting documents: ", error);
                }).finally(() => {
                this.loading = false;
            });
        },
        },
        mounted() {
           this.fetchList();
        }
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question