我的任务是做分页和搜索。我通过创建两个计算属性解决了这个问题(形象地我可以称它们为过滤器)。单独地,它们可以正常工作,但我需要将它们联合起来。我不知道该怎么做?
我的 html:
<li v-for="(post, index) of paginatedData" class="post">
<p><span class="boldText">Title:</span> {{ post.title }}</p>
<p><span class="boldText">Content:</span> {{ post.body }}</p>
</li>
我的 Vue.js(我的两个过滤器):
paginatedData() {
const start = this.page * 10;
const end = start + 10;
return this.posts.slice(start, end);
},
filteredPosts() {
return this.posts.filter((post) => {
return post.title.match(this.search);
});
},
最佳答案
在 paginatedData
方法中进行过滤,并对过滤后的数组进行切片。
paginatedData() {
const start = this.page * 10;
const end = start + 10;
return this.posts.filter((post) => {
return post.title.match(this.search);
}).slice(start, end);
}
关于javascript - 如何用两个过滤器制作一个过滤器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55541658/