#14 simple blog : front - home view
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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" })
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user