Answer the question
In order to leave comments, you need to log in
How to properly filter an array?
I have a component with an array and two filters: by type and by date.
export default {
data() {
date: null,
type: 'photo',
posts: [{type:'photo', date: 147852369}, /* ... */]
}
}
computed {
filteredPosts() {
return this.posts.filter(p => p.date > this.date && p.type === this.type)
}
}
computed {
filterByType() {
return this.filterByDate.filter(p => p.date > this.date)
},
filterByDate() {
return this.posts.filter(p => p.type === this.type)
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question