0

I am trying to update my Vue component's state by getting a reference to a node in firebase, iterate through all its children and store it into a variable. Any idea on how to do that? I am not able to access any of my component's global, data, or state variables within firebase's '.on' functions.

This is my data for my vue component

data () {
return {
  authID  : '',
  tab_names : ['tab']
}
},

Where tab_names is an array list where I would to push new variables from firebase.

tabList.on('value', function(snapshot){
  snapshot.forEach(function(child){
      var key = child.key;
      var value = child.val();
      //cant access this.tab_names, or even variables from vuex store
  });
});

Because I cannot access any variables to update my state, how would I go about solving this? Sorry

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
IWantToLearn
  • 21
  • 1
  • 6
  • Have you considered: [VuexFire](https://github.com/posva/vuexfire) : https://jsfiddle.net/posva/6w3ks04x/ – Randy Casburn Apr 03 '18 at 22:33
  • Simply use an arrow function, eg `tabList.on('value', snapshot => { snapshot.forEach(child => ...`. Then you can access `this.tab_names` – Phil Apr 03 '18 at 23:16

0 Answers0