diff options
Diffstat (limited to 'components/Posts/PostList/PostList.vue')
-rw-r--r-- | components/Posts/PostList/PostList.vue | 45 |
1 files changed, 12 insertions, 33 deletions
diff --git a/components/Posts/PostList/PostList.vue b/components/Posts/PostList/PostList.vue index 781099f..80369a8 100644 --- a/components/Posts/PostList/PostList.vue +++ b/components/Posts/PostList/PostList.vue @@ -1,9 +1,8 @@ <template> - <pure-post-list v-if="rawPosts" :posts="posts" :loading="loading" /> + <pure-post-list v-if="posts" :posts="parsedPosts" :loading="loading" /> </template> <script> -import k from '~/api' import PurePostList from './PurePostList' export default { @@ -12,43 +11,23 @@ export default { props: { max: { type: Number, + required: false, + default: () => 4 + }, + posts: { + type: Array, required: false } }, - data() { - return { - loading: true, - rawPosts: undefined - } - }, - mounted() { - if (process.client && this.rawPosts === undefined) { - this.loadPostsClient() - } else { - this.rawPosts = k.getPosts() - this.loading = false - } - }, computed: { - posts() { + parsedPosts() { if (this.max) { - return this.rawPosts.slice(0, this.max) + return this.posts.slice(0, this.max) } - return this.rawPosts - } - }, - methods: { - async loadPostsClient() { - let posts = await this.$axios.get( - `${window.location.origin}/api/posts.json` - ) - this.rawPosts = posts.data - this.rawPosts = this.rawPosts.map(post => ({ - title: post.content.meta.title, - description: post.content.description, - route: post.route - })) - this.loading = false + return this.posts + }, + loading() { + return this.posts === undefined } } } |