I don’t know how to get the data via
this.$fire.database
I’ve read the firebase docs but in firebase/nuxtJs different it becomes easier https://firebase.nuxtjs.org/
In firebase docs
import { getDatabase, ref, onValue} from "firebase/database"; const db = getDatabase(); const starCountRef = ref(db, 'posts/' + postId + '/starCount'); onValue(starCountRef, (snapshot) => { const data = snapshot.val(); updateStarCount(postElement, data); });
But when I call onValue, it doesn’t find it
this.$fire.database.onValue()
nuxt.config.js file
modules: [ // https://go.nuxtjs.dev/axios '@nuxtjs/axios', [ '@nuxtjs/firebase', { config: { apiKey: "<private data>", authDomain: "<private data>", projectId: "<private data>", storageBucket: "<private data>", messagingSenderId: "<private data>", appId: "<private data>" }, services: { auth: true, // Just as example. Can be any other service. database: { emulatorPort: 3000, emulatorHost: 'localhost', } }, } ] ],
Advertisement
Answer
Simply
this.$fire.database.ref('name').on("value", function(e) { console.log(e.val()) })
simple explanation :
ref("name")
Whenever the value is changed, the function will run