74 lines
2.1 KiB
Vue
74 lines
2.1 KiB
Vue
<template>
|
|
<SMPage class="news-list">
|
|
<template #container>
|
|
<SMMessage
|
|
v-if="message"
|
|
icon="alert-circle-outline"
|
|
type="error"
|
|
:message="message"
|
|
class="mt-5" />
|
|
<SMPanelList
|
|
:loading="loading"
|
|
:not-found="posts?.length == 0"
|
|
not-found-text="No news found">
|
|
<SMPanel
|
|
v-for="post in posts"
|
|
:key="post.id"
|
|
:image="post.hero"
|
|
:to="{ name: 'post-view', params: { slug: post.slug } }"
|
|
:title="post.title"
|
|
:date="post.publish_at"
|
|
:content="post.content"
|
|
:show-date="false"
|
|
button="Read More"
|
|
button-type="outline" />
|
|
</SMPanelList>
|
|
</template>
|
|
</SMPage>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { reactive, ref } from "vue";
|
|
import { api } from "../helpers/api";
|
|
import SMMessage from "../components/SMMessage.vue";
|
|
import SMPanelList from "../components/SMPanelList.vue";
|
|
import SMPanel from "../components/SMPanel.vue";
|
|
import SMPage from "../components/SMPage.vue";
|
|
import { SMDate } from "../helpers/datetime";
|
|
import { PostCollection, Post } from "../helpers/api.types";
|
|
|
|
const message = ref("");
|
|
const loading = ref(true);
|
|
let posts: Array<Post> = reactive([]);
|
|
|
|
const handleLoad = async () => {
|
|
message.value = "";
|
|
|
|
api.get({
|
|
url: "/posts",
|
|
params: {
|
|
limit: 5,
|
|
},
|
|
})
|
|
.then((result) => {
|
|
const data = result.data as PostCollection;
|
|
|
|
posts = data.posts;
|
|
posts.forEach((post) => {
|
|
post.publish_at = new SMDate(post.publish_at, {
|
|
format: "ymd",
|
|
utc: true,
|
|
}).format("yyyy/MM/dd HH:mm:ss");
|
|
});
|
|
})
|
|
.catch((error) => {
|
|
message.value =
|
|
error.data?.message || "The server is currently not available";
|
|
});
|
|
|
|
loading.value = false;
|
|
};
|
|
|
|
handleLoad();
|
|
</script>
|