Good day! How do I display all data from PocketBase to VueJS 3
Still new to Vue, Idk why it displays only one data.
Tried using v-for
but it causes render errors.
Any solutions to this? Thank you.
JavaScript
x
33
33
1
<template>
2
<div class="about">
3
<h1>This is an about page</h1>
4
5
<p>{{ posts.title }}</p>
6
7
<button @click="loadPosts">Load</button>
8
9
</div>
10
</template>
11
12
<script setup>
13
import { ref } from 'vue'
14
import client from '@/module/pb.js'
15
16
const posts = ref({})
17
18
async function loadPosts() {
19
20
const records = await client.records.getFullList('posts', 200, {
21
sort: '-created',
22
});
23
24
records.forEach(post => {
25
posts.value = post
26
});
27
28
console.log(records)
29
30
}
31
32
</script>
33
Advertisement
Answer
With
JavaScript
1
4
1
records.forEach(post => {
2
posts.value = post
3
});
4
you are overwriting post, so at the end you have one value. Try like:
JavaScript
1
2
1
posts.value = records
2
and then use v-for
to show all the posts