Skip to content

Commit

Permalink
Merge pull request #10 from KensukeOta/記事詳細表示機能
Browse files Browse the repository at this point in the history
記事詳細表示機能を実装しました
  • Loading branch information
KensukeOta authored Jun 15, 2022
2 parents 72376ba + 0aa1b9a commit 3995186
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/components/organisms/PostItem.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script setup lang="ts">
import type { Post } from "@/types/Post";
import { RouterLink } from "vue-router";
defineProps<{
post: Post;
Expand All @@ -8,7 +9,9 @@ defineProps<{

<template>
<li class="border">
<h1 class="font-bold">{{ post.title }}</h1>
<RouterLink :to="`/posts/${post.id}`">
<h1 class="font-bold">{{ post.title }}</h1>
</RouterLink>
<nav>
<p>by {{ post.user.name }}</p>
</nav>
Expand Down
6 changes: 6 additions & 0 deletions src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import HomeView from "@/views/HomeView.vue";
import SignupView from "@/views/SignupView.vue";
import LoginView from "@/views/LoginView.vue";
import PostFormView from "@/views/PostFormView.vue";
import PostContentView from "@/views/PostContentView.vue";

const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
Expand All @@ -27,6 +28,11 @@ const router = createRouter({
name: "posts_create",
component: PostFormView,
},
{
path: "/posts/:id",
name: "post_content",
component: PostContentView,
},
],
});

Expand Down
20 changes: 20 additions & 0 deletions src/views/PostContentView.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<script setup lang="ts">
import type { Post } from '@/types/Post';
import { onMounted, ref } from 'vue';
import { useRoute } from 'vue-router';
import { axios } from '@/lib/axios';
const post = ref<Post>();
const route = useRoute();
onMounted(async () => {
const res = await axios.get(`${import.meta.env.VITE_API_URL}/api/posts/${route.params.id}`);
post.value = res.data;
});
</script>

<template>
<h1 class="font-bold">{{ post?.title }}</h1>
<p>{{ post?.body }}</p>
</template>

1 comment on commit 3995186

@vercel
Copy link

@vercel vercel bot commented on 3995186 Jun 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.