【发布时间】:2020-10-04 09:29:45
【问题描述】:
我收到此错误。我正在尝试使用我的搜索栏(输入)过滤我的数组 我正在按照计算进行搜索操作。
<div class="post"
@click="getData(post.header,post.text)"
v-for="(post) in searchList"
v-bind:item="post"
v-bind:key="post._id"
>
计算属性
computed:{
searchList() {
return this.posts.filter(post => {
return post.text.toLowerCase().includes(this.lookfor.toLowerCase())
})
}
},
请帮帮我,谢谢
【问题讨论】:
-
似乎至少对于您的
posts之一,post.text不是字符串。在你的filter回调中添加一些像这样的简单调试怎么样~console.log(typeof post.text, post.text) -
你可以简单地返回
return post.text && post.text.toLowerCase().includes(this.lookfor.toLowerCase()) -
@Jhecht 这不太可能奏效。如果
post.text是null或undefined,则错误消息会有所不同。话虽如此,对于某些记录,post.text可能是布尔值false -
您需要检查您的 post.text。只有
String的类型有方法.toLowerCase()