Search code examples
firebasefirebase-realtime-databasevue.jsquasar

VueJS/Quasar: How do I pass data fetched from FirebaseDB in "mounted" function and use it in "data" so I can display it in my HTML


myjfc is a variable that contains the data from my Firebase DB. I don't know how to pass it around - pass it to data so I can display it in my DOM.

data(){

   return{

       question1: "I_WANT_TO_ASSIGN_DATA_FROM_FIREBASE_HERE"
    }
},

mounted(){  
        this.$firebase.database().ref('questions').on('value', data => {
        const obj = data.val()
        var myjfc = obj.question1.a

        return myjfc //this contains the data I want to use
   })
 }

Any kind of help is appreciated.


Solution

  • Ok if anyone is encountering this, with help from Quasar community @Robin, here's how:

    data(){
       return{
           question1: ''
        }
    },
    
    mounted(){  
            this.$firebase.database().ref('questions').on('value', data => {
            const obj = data.val()
            this.question1 = obj.question1.a
       })
     }
    

    Can't believe I missed that!