From aa4402294b3fe978f8694436ae4478eda071e7b2 Mon Sep 17 00:00:00 2001 From: Adam French Date: Wed, 10 Dec 2025 16:48:17 +0000 Subject: [PATCH] added posts --- nginx/vue/src/components/home/Feed.vue | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/nginx/vue/src/components/home/Feed.vue b/nginx/vue/src/components/home/Feed.vue index b9a30a8..d9ad826 100644 --- a/nginx/vue/src/components/home/Feed.vue +++ b/nginx/vue/src/components/home/Feed.vue @@ -2,29 +2,49 @@ import { ref, onMounted } from "vue"; import axios from "axios"; -const posts = ref([]); +const post = ref(null); +const fetched = ref(false); +let posts = []; +let idx = 0; +let len = 0; + async function fetchPosts() { try { const res = await axios.get("https://adam-french.co.uk/api/posts"); posts.value = res.data; + fetched.value = true; + post.value = posts[0]; + len = posts.length; } catch (err) { console.error(err); } } +function nextPost() { + post.value = posts[idx]; + idx = (idx + 1) % len; +} + +function prevPost() { + post.value = posts[idx]; + idx = (idx - 1) % len; +} + onMounted(() => { fetchPosts(); });