Fetching Database Records in Vue Application
I’m having trouble displaying data from an external database in my Vue component. I’ve been working on this for several hours but can’t seem to get the records to show up in my template.
I’m using a database API package to fetch the data, but the records array stays empty. Here’s my current setup:
<template>
<div class="content-wrapper">
<div class="container">
<h2>{{ title }}</h2>
<div class="data-grid">
<ProductCard />
<ul class="items-list">
<li v-for="entry in dataEntries" :key="entry">
Content: {{ entry }}
</li>
</ul>
</div>
</div>
</div>
</template>
<script>
import ProductCard from "../components/ProductCard.vue";
import DatabaseAPI from "database-package";
export default {
name: "Dashboard",
components: {
ProductCard,
},
props: {
title: String,
},
data() {
return {
dataEntries: [],
};
},
mounted() {
const connection = new DatabaseAPI({ token: "my-api-token" }).connect(
"my-database-id"
);
connection("Products")
.query({
filter: "Main view",
})
.getAll(function (error, results) {
if (error) {
console.log(error);
return;
}
results.forEach((result) => {
console.log(result.field("Title"));
return result.field("Title");
});
});
},
};
</script>
The console shows the data correctly, but my dataEntries array remains empty. What am I missing to populate the reactive data properly?