我正在尝试使用 electron-vue 以 .vue 文件中的方法从 NeDB 获取数据。我知道我可以通过将它放入一个变量来得到它,但我想通过'return'得到它,因为我想在 v-for 中使用结果。
我尝试使用 bluebird promisify 和 async/await 但它不起作用。
数据存储.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
测试.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>
我得到“未捕获(承诺)类型错误:无法读取未定义的属性'推送'”。
我可以从由此创建的数据库中获取数据:
this.$db.find({}, function (err, doc) {
console.log(err)
console.log(doc)
this.list = doc || []
}.bind(this))
请帮我....