I am trying to display a list of images and I get the images from the backend as follows:
const postimages = ref({});
const productimages = ref({});
onBeforeMount(async () => {
let imagesdata = await axios.get(
"api/v1/posts/user/" + loggedUser + "/posts/images/"
);
for (var post of imagesdata.data) {
if (post.type == "post") {
postimages.value = post.images;
console.log(postimages.value)
}
if (post.type == "product") {
productimages.value = post.image;
}
}
});
The console.log statement prints the following:
Proxy { <target>: (4) […], <handler>: {…} }
<target>: Array(4) [ {…}, {…}, {…}, … ]
0: Object { id: 43, image: "http://127.0.0.1:8000/storage/posts/45/images/landscape-tree-water-nature-forest-wilderness-1267115-pxhere.com.jpg", created_at: "2022-12-27T06:15:56.022681Z" }
1: Object { id: 42, image: "http://127.0.0.1:8000/storage/posts/45/images/bourkes-potholes-2-kruger-park-big-five-african-travel-desk.jpg", created_at: "2022-12-27T06:15:56.020644Z" }
2: Object { id: 41, image: "http://127.0.0.1:8000/storage/posts/45/images/kilimanjaro.jpg", created_at: "2022-12-27T06:15:56.018705Z" }
3: Object { id: 40, image: "http://127.0.0.1:8000/storage/posts/45/images/Lake-Tahoe-Beauty.jpg", created_at: "2022-12-27T06:15:56.016182Z" }
length: 4
<prototype>: Array []
<handler>: Object { get: get(target, key, receiver), set: set(target, key, value, receiver), deleteProperty: deleteProperty(target, key)
, … }
MediaView.vue:148
Proxy { <target>: [], <handler>: {…} }
<target>: Array []
length: 0
<prototype>: Array []
<handler>: Object { get: get(target, key, receiver), set: set(target, key, value, receiver), deleteProperty: deleteProperty(target, key)
, … }
MediaView.vue:148
Proxy { <target>: [], <handler>: {…} }
<target>: Array []
length: 0
<prototype>: Array []
<handler>: Object { get: get(target, key, receiver), set: set(target, key, value, receiver), deleteProperty: deleteProperty(target, key), … }
In the template I have the following:
<div class="imagesList flex wrap" v-if="postimages">
{{ postimages }}
<div
class="imageList"
v-for="(image, id) in postimages"
:key="id"
>
<div class="imageList" v-for="(img, id) in image" :key="id">
<img :src="img.image" class="listImg" />
</div>
</div>
</div>
Why is the {{postimages}} part giving me an empty array and why are none of the images displayed with the v-form loop?