0
I’m new to Vue and Firebase, I have the following problem: I want to return the generated value inside then, in the console.log that is inside then returns the id that was generated, but when I refer the same id outside then I get a Undefined.
enviarDados(){
db.collection('teste').add(this.user)
.then((docRef) => {
this.idGerado = docRef.id
console.log('Meu id:', this.idGerado)
})
.catch((error) => {
console.error("Error adding document: ", error);
});
console.log(this.idGerado)
}
Related
– Wallace Maxters
There are quite duplicate of this question here on the site. Basically, Promise is used to get a value "in another timeline", so you will only be able to get the value within the
then. To solve this, you can use callback functions to work on top ofdocRef.id.– Wallace Maxters