使用我的搜索栏Vuejs2过滤数组的错误
我正在尝试通过使用搜索栏过滤一个循环在V-For中的数组,但我不知道为什么一切都消失了。我目前正在骑自行车搜索搜索的功能()。 这是我遇到的错误:this.all_restaurants.filter不是一个函数。 这是我的代码:
<div class="col" v-for="(restaurant, index) in searchedRestaurant()" :key="index">
data() {
return{
all_categories: {},
all_restaurants: {},
search: ""
}
},
computed: {
searchedRestaurant: function(){
return this.all_restaurants.filter((element) => {
return element.business_name.match(this.search)
})
}
}
I'm trying to filter an array, which is cycled in a v-for, by using a search bar and i don't know why everything just disappear.I am currently cycling the function searchedRestaurant().
This is the error I got: this.all_restaurants.filter is not a function.
This is my code:
<div class="col" v-for="(restaurant, index) in searchedRestaurant()" :key="index">
data() {
return{
all_categories: {},
all_restaurants: {},
search: ""
}
},
computed: {
searchedRestaurant: function(){
return this.all_restaurants.filter((element) => {
return element.business_name.match(this.search)
})
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
all_categories
和all_restaurants
应该是数组all_categories
andall_restaurants
should be arrays