我正在使用Vue重建我的WordPress博客。我正在尝试显示我的最近的3篇文章,我在这里进行了操作:
<template>
<section>
<h4>最近的文章</h4>
<div class="posts-recent">
<div v-for="(post, index) in posts.slice(0, 3)" :key="post.id" class="post">
<div :key="index">
<nuxt-link :to="`/blog/${post.slug}`" class="post-image" :style="{ backgroundImage: 'url(' + post.fimg_url + ')' }"></nuxt-link>
<div class="post-text">
<nuxt-link :to="`/blog/${post.slug}`" class="post-title" v-html="post.title.rendered"></nuxt-link>
</div>
</div>
</div>
</div>
</section>
</template>
<script>
import { mapState, mapActions } from 'vuex';
export default {
name: 'Recent',
created() {
this.getPosts();
},
props: {
slug: String
},
computed: {
...mapState(['posts']),
},
methods: {
...mapActions(['getPosts']),
}
};
</script>
这个代码可以正常工作,但是我希望在显示3篇文章的同时,排除当前的文章,如果当前的文章是最近的3篇文章之一。
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号