fix too many v-if
This commit is contained in:
@@ -8,7 +8,15 @@ import { useAuthStore } from "@/stores/auth";
|
||||
const auth = useAuthStore();
|
||||
const userOwnsPost = ref(false);
|
||||
|
||||
const post = ref(null);
|
||||
const post = ref({
|
||||
title: "Can't fetch from the db yo",
|
||||
content:
|
||||
"This is meant to be pulling from a database, but for some reason that isn't working and this is filler text that should hopefully never see the light of day. If you are reading this, something has gone horribly, horribly wrong. Please start crying and prepare for the incoming wrath of hell. Furthermore, this is very, very long because I am trying to test the scroll feature so thank you ^_^.",
|
||||
author: {
|
||||
username: "stp",
|
||||
},
|
||||
createdAt: Date.now(),
|
||||
});
|
||||
const leftCap = ref(false);
|
||||
const rightCap = ref(false);
|
||||
let posts = [];
|
||||
@@ -17,14 +25,17 @@ let len = 0;
|
||||
|
||||
async function fetchPosts() {
|
||||
try {
|
||||
const res = await axios.get("https://www.adam-french.co.uk/api/posts");
|
||||
posts = res.data;
|
||||
len = posts.length;
|
||||
post.value = posts[0];
|
||||
|
||||
userOwnsPost.value = post.value.author.username == auth.user.username;
|
||||
|
||||
leftCap.value = true;
|
||||
const res = await axios.get("/api/posts");
|
||||
if (Array.isArray(res.data)) {
|
||||
posts = res.data;
|
||||
len = posts.length;
|
||||
post.value = posts[0];
|
||||
userOwnsPost.value =
|
||||
post.value.author.username == auth.user.username;
|
||||
leftCap.value = true;
|
||||
} else {
|
||||
throw new Error("Invalid response from API");
|
||||
}
|
||||
} catch (err) {
|
||||
console.log("Cannot connect to API");
|
||||
}
|
||||
@@ -66,7 +77,7 @@ onMounted(() => {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="post" class="flex-col pad scroll-y left-content">
|
||||
<div class="flex-col pad scroll-y left-content">
|
||||
<h2>{{ post.title }}</h2>
|
||||
<Markdown class="fill wrap" :source="post.content" />
|
||||
<p>by: {{ post.author.username }}</p>
|
||||
@@ -81,24 +92,6 @@ onMounted(() => {
|
||||
</div>
|
||||
<button v-if="userOwnsPost" @click="deletePost">Delete</button>
|
||||
</div>
|
||||
<div class="flex-col pad left-content" v-else>
|
||||
<h2>Can't fetch from the db yo</h2>
|
||||
<div class="fill wrap scroll-y">
|
||||
This is meant to be pulling from a database, but for some reason
|
||||
that isn't working and this is filler text that should hopefully
|
||||
never see the light of day. If you are reading this, something has
|
||||
gone horribly, horribly wrong. Please start crying and prepare for
|
||||
the incoming wrath of hell. Furthermore, this is very, very long
|
||||
because I am trying to test the scroll feature so thank you ^_^.
|
||||
</div>
|
||||
<p>by: stp</p>
|
||||
<small>Created at: 0/0/0</small>
|
||||
<div class="flex-row fill-width">
|
||||
<button class="fill">Prev</button>
|
||||
<button class="fill">Next</button>
|
||||
</div>
|
||||
<button>Delete</button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
|
||||
Reference in New Issue
Block a user