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.
And, of course, this App interacts with Firebase Firestore as backend infrastructure:
Demo
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:
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:
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:
Top comments (0)