Skip to content
☁️ Cloud Firestore binding in realtime with Vuejs
Branch: master
Clone or download
Latest commit 2aa0d02 Feb 26, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
dist build Feb 23, 2019
src Define the default plugin oprions Feb 23, 2019
tests Add tests Jan 6, 2019
.babelrc update .babelrc Mar 6, 2018
.eslintrc standard eslint conf May 26, 2018
.gitignore update .gitignore Mar 6, 2018
.npmignore Create .npmignore Jan 6, 2019
.travis.yml Update .travis.yml Dec 13, 2018
LICENSE add MIT license Oct 21, 2017 Update Feb 26, 2019
package.json increment version Feb 23, 2019
webpack.config.js update webpack Mar 6, 2018


Vue.js binding for firebase cloud firestore.


Firebase ^5.0.0

Try it out: Demo


Globally (Browser)

vue-firestore will be installed automatically.

<!-- Vue -->   
<script src=""></script>
<!-- Firebase -->   
<script src=""></script>
<!-- Firestore -->   
<script src=""></script>
<!-- vue-firestore -->   
<script src=""></script>

  // Firebase config.
  var config = {
        apiKey: "your-apik-ey",
        authDomain: "your-auth-domain",
        databaseURL: "your-database-url",
        projectId: "your-project-id",
        storageBucket: "your-storage-bucket",
        messagingSenderId: "your-messaing-sender-id"

  // Initialize Firebase.


Installation via npm : npm install vue-firestore --save


vue-firestore supports binding for the both (collections/docs) in realtime, you can bind your properties in two ways using firestore option or bind them manually with $binding.

  1. using firestore option.
import Vue from 'vue'
import VueFirestore from 'vue-firestore'
import Firebase from 'firebase'



var firebaseApp = Firebase.initializeApp({ ... })

const firestore = firebaseApp.firestore();

var vm = new Vue({
  el: '#app',
  firestore () {
    return {
        // Collection
        persons: firestore.collection('persons'),
        // Doc
        ford: firestore.collection('cars').doc('ford')

You can pass an object to the firestore() function.

As you may know, firestore source returns a promise, so you can handle it if it's resolved by resolve function or rejected by reject function, this case is really useful when we want to wait for data to be rendered and do some specific actions.

firestore () {
  return {
    persons: {
      // collection reference.
      ref: firestore.collection('persons'),
      // Bind the collection as an object if you would like to.
      objects: true,
      resolve: (data) => {
          // collection is resolved
      reject: (err) => {
          // collection is rejected
  1. Manually binding

You can bind your docs/collection manually using this.$binding, and wait for data to be resolved, this case is really useful when we want to wait for data to be rendered and do some specific actions.

mounted () {
  // Binding Collections
  this.$binding("users", firestore.collection("users"))
  .then((users) => {
    console.log(users) // => __ob__: Observer

  // Binding Docs
  this.$binding("Ford", firestore.collection("cars").doc("ford"))
  .then((ford) => {
    console.log(ford) // => __ob__: Observer
  }).catch(err => {

Vue firestore latest release supports binding collections as objects, you can bind the collection manually by this.$bindCollectionAsObject(key, source) or you can explicitly do that by adding {objects: true} to firestore() function, see the previous example above.

The normalized resutls of $bindCollectionAsObject:

    tjlAXoQ3VAoNiJcka9: {
        firstname: "Jhon",
        lastname: "Doe"
    fb7AcoG3QAoCiJcKa9: {
        firstname: "Houssain",
        lastname: "Amrani"

You can get access to firestore properties with this.$firestore.

Adding Data to collections

var vm = new Vue({
  el: '#app',
  firestore: function () {
    return {
        persons: firestore.collection('persons')
    addData: function () {
            firstname: "Amrani",
            lastname: "Houssain"

Each record of the array will contain a .key property which specifies the key where the record is stored.

The Result of persons collection will be normalized as :

        ".key": "-Jtjl482BaXBCI7brMT8",
        "firstname": "Amrani",
        "lastname": "Houssain"
        ".key": "-JtjlAXoQ3VAoNiJcka9",
        "firstname": "John",
        "lastname": "Doe"

You could delete or update a json document of a collection using the property .key of a given object.

// Vue methods
deletePerson: function (person) {
updatePerson: function (person) {
        name: "Amrani Houssain"
        github: "@amranidev"

You can customize the name of the .key property by passing an option when initializing vue-firestore:


Vue.use(VueFirestore, {
    key: 'id',         // the name of the property. Default is '.key'.
    enumerable: true  //  whether it is enumerable or not. Default is true.

This would allow you to do instead of person['.key'].

More Resources



You can’t perform that action at this time.