#14 simple blog : front - home view

This commit is contained in:
haerong22
2022-08-01 00:32:33 +09:00
parent 57a3b7bf6f
commit 7111441e72
2 changed files with 26 additions and 2 deletions

View File

@@ -1,7 +1,26 @@
<script setup lang="ts">
import axios from "axios";
import {ref} from "vue";
const posts = ref([]);
axios.get("/api/posts?page=1&size=5", ).then((response) => {
response.data.forEach((r: any) => {
posts.value.push(r);
})
})
</script>
<template>
<main>
</main>
<ul>
<li v-for="post in posts" :key="post.id">
<div>
{{ post.title }}
</div>
<div>
{{ post.content }}
</div>
</li>
</ul>
</template>

View File

@@ -1,15 +1,20 @@
<script setup lang="ts">
import {ref} from "vue";
import axios from "axios";
import {useRouter} from "vue-router";
const title = ref("");
const content = ref("");
const router = useRouter();
const write = () => {
axios.post("/api/posts", {
title: title.value,
content: content.value,
})
.then(() => {
router.replace({ name: "home" })
});
}