DEV Community

loizenai
loizenai

Posted on

Vue.js Firestore example - Vue.js CRUD serverless with Firebase Cloud Firestore

https://grokonez.com/frontend/vue-js/vue-js-firestore-example-vue-js-crud-serverless-with-firebase-cloud-firestore

Cloud Firestore helps us store data in the cloud. It supports offline mode so our app will work fine (write, read, listen to, and query data) whether device has internet connection or not, it automatically fetches changes from our database to Firebase Server. We can structure data in our ways to improve querying and fetching capabilities. This tutorial shows you a Vue.js app that can do Firebase Firestore CRUD Operations.

Related Post: Vue.js CRUD example – a simple Note App

Vue.js Firestore example Overview

Goal

Our Vue App can help us write new Notes, then it displays a list of Notes and each Note page (containing title and content) can be modified easily. This App also supports offline mode - we can create/update/delete Note without internet connection.

vuejs-firestore-example-crud-note-app-overview

And, of course, this App interacts with Firebase Firestore as backend infrastructure:

vuejs-firestore-example-note-app-firebase-firestore-result

Demo

Project Structure

vuejs-firestore-example-crud-note-app-project-structure

We have 3 components:

  • App.vue holds all of the other components.
  • NotesList.vue contains all of notes in a List with + Note button.
  • Note.vue display a single Note in the List that allows us to create new Note or edit current Note.

    Technologies

  • Vue CLI 3.0.1
  • Vue 2.5.17
  • Firebase SDK for Javascript 5.4.2

    Practice

    Setup Vue Project

    Install vue-cli

    For use Vue CLI anywhere, run command: npm install -g vue-cli

    Init Project

    Point cmd to the folder you want to save Project folder, run command: npm create vue-note-app

You will see 2 options, choose default:

vuejs-firestore-example-note-app-project-setup

Install Firebase SDK

Run command: npm install firebase
Once the process is done, you can see firebase in package.json:

"dependencies": {
  "firebase": "^5.4.2",
  "vue": "^2.5.17"
},

Setup Firebase Project

Create Project

Go to Firebase Console, login with your Google Account, then click on Add Project.

Enter Project name, select Location:

vuejs-firestore-example-note-app-add-firebase-project

Then press CREATE PROJECT.

Config Rules for Firebase Cloud Firestore

On the left tab, click on Database.
Choose Cloud Firestore. Click on Create Database, a window is shown, choose Start in test mode:

vuejs-firestore-example-note-app-add-firebase-database-rule

More at: https://grokonez.com/frontend/vue-js/vue-js-firestore-example-vue-js-crud-serverless-with-firebase-cloud-firestore

Top comments (0)