Seeking assistance on retrieving data from NeDB within a method in a .vue file using electron-vue. Currently, I am aware that the data can be stored in a variable, but my preference is to fetch it using 'return' as I intend to utilize the result in a v-for loop.
Attempts were made utilizing bluebird promisify and async/await, however, without success.
datastore.js
import Datastore from 'nedb'
import path from 'path'
import { remote } from 'electron'
export default new Datastore({
autoload: true,
filename: path.join(remote.app.getPath('userData'), '/data.db')
})
main.js
import db from './datastore'
Vue.prototype.$db = db
test.vue
<template>
<div>
<ul>
<li v-for="member in memberName">
{{ member.name }}({{ member.relation }}){{ member._id }}
<ul>
<li v-for="game in filterByName(member._id)">
{{ game }}
</li>
</ul>
</li>
</ul>
</div>
</template>
<script>
import Promise from 'bluebird'
export default {
// some data
created: function () {
this.dbFindAsync = Promise.promisify(thistest.$db.find)
},
methods: {
filterByName: async function (id) {
const docs = await this.dbFindAsync({ 'members.nameId': id }, { 'members': 1, _id: 0 })
console.log(docs)
return docs
},
// some other methods
}
}
</script>
An error "Uncaught (in promise) TypeError: Cannot read property 'push' of undefined" occurred.
Data retrieval from DB during creation using:
this.$db.find({}, function (err, doc) {
console.log(err)
console.log(doc)
this.list = doc || []
}.bind(this))
In need of assistance....