0

in the folowing code, after i update field collection it would not update "this.fields" (which is bound to tha collection in store.js by vuexfire rules) - only when i refresh page. please help. thanks

var newField = {
      name: this.fieldName,
      area: this.fieldArea,
      farmId: this.farmId
    }

    var docRef = fb.field.doc()
    docRef.set(newField)
    var id = docRef.id

    console.log(id)
    fb.field
      .doc(id)
      .get()
      .then(ref => {
        this.$store.commit('updateCurrentField', ref.data())
      })
Orsha
  • 1

1 Answers1

0

How, and where, are you getting the this.fields?

Is it a computed property?

it should be somthing arround the lines of this in order to keep the data updated (vuex documentation)

computed: {
 fields() {
   this.$store.state.fields
 }
}
Atlow
  • 83
  • 5
  • hi, thanks for helping. i'm getting it using map getters like so: ...mapGetters([fields]) inside computed, and in store.js it looks like this: fields: state => { return state.fields }, – Orsha Jun 19 '20 at 04:35
  • Do you use the vue devtools? Does the store stay updated in the devtools? – Atlow Jun 19 '20 at 06:23
  • i got it working by setting up the document id in the new object i created, then i added it to firestore. that's wierd, but it works this way.. thanks anyway! =) – Orsha Jun 19 '20 at 12:30