[Vuejs]-Use doc as computed property (Vue, nedb, Electron)

0๐Ÿ‘

No need for promises or async/await. You could simply set a local data property in your $db.insert callback (convert that to an arrow-function beforehand to preserve context):

// script
export default {
  data() {
    return {
      doc: null, ๐Ÿ‘ˆ
    }
  },
  methods: {
    savePreset() {
      ...
      this.$db.insert(doc, (err, newDoc) => {
        if (err) {
          console.log(err)
        } else {
          console.log(newDoc)

          this.doc = newDoc ๐Ÿ‘ˆ
        }
      })
    }
  }
}

//template
<ul>
  <li v-for="(val, key) in doc" v-if="val">{{key}}: {{val}}</li>
</ul>

Edit Iterating an object with v-for

Leave a comment