我正在尝试创建简单的 Vue + CouchDB 应用程序。使用 Vanilla JS 可以正常工作,但我无法通过 Promise 或异步函数从数据库获取数据到我的 vue 实例。这是我的代码:
应用程序.html
<div id="vue-app">
<table>
<thead>
<tr>
<th>{{ tableHead.name }}</th>
<th>{{ tableHead.lastname }}</th>
</tr>
</thead>
<tbody>
<tr v-for="data in tableData">
<td>{{ data.name }}</td>
<td>{{ data.lastname }}</td>
</tr>
</tbody>
</table>
</div>
Run Code Online (Sandbox Code Playgroud)
应用程序.js
const db = new PouchDB('testdb')
const couch = {
fetchData: async function () {
var dbData = await db.allDocs({
include_docs: true,
descending: true
}).then(function (result) {
var objects = {}
result.rows.forEach(function (data) {
objects[data.id] = data.doc
})
return …Run Code Online (Sandbox Code Playgroud)