我正在构建一个博客应用程序,我想在主页上呈现最新的帖子,我使用Vue和Nuxt和Storyblok作为后端/cms。
目前,我正在显示来自post数组的所有帖子,是否有一种方法只显示多个帖子,或者更好地显示来自post数组的最新帖子?
<template>
<section class="container">
<PostList :posts="loadedPosts" class="post-list" />
</section>
</template>
export default {
components: {
PostList,
Aside
},
computed: {
loadedPosts() {
return this.$store.getters.loadedPosts.map(bp => {
return {
id: bp.slug,
title: bp.content.title,
previewText: bp.content.summary,
thumbnailUrl: bp.content.thumbnail
};
});
}
}我想从我的帖子中得到最后3-4个帖子。
发布于 2019-09-16 13:52:19
this.$store.getters.loadedPosts似乎是一个数组。要只获得前4项,您必须对其进行切片(假设最近的帖子是数组中的第一条)。
loadedPosts() {
return this.$store.getters.loadedPosts.slice(0, 4).map(bp => {
return {
id: bp.slug,
...
};
});
}https://stackoverflow.com/questions/57952728
复制相似问题