vue 实现数组筛选功能 filter过滤
相信小伙伴们都写过数组过滤吧。在某一个列表上面,有一个input框,搜索列表中的某个值,来进行筛选。我们可以利用数组的filter方法来实现。注:v_tableList: 列表需要的数据v_filterKeyword: 搜索框双向绑定的keyv_detailList: 后台拿的数据computed: {v_tableList () {if (this.v_filterKeyword !== '')
·
相信小伙伴们都写过数组过滤吧。在某一个列表上面,有一个input框,搜索列表中的某个值,来进行筛选。
我们可以利用数组的filter方法来实现。
注:
- v_tableList: 列表需要的数据
- v_filterKeyword: 搜索框双向绑定的key
- v_detailList: 后台拿的数据
computed: {
v_tableList () {
if (this.v_filterKeyword !== '') {
let keyword = this.v_filterKeyword.toLowerCase()
return this.v_detailList.filter(item => {
// 以name来搜索
let str = item.name.toLowerCase()
return str.indexOf(keyword) !== -1
})
} else {
return this.v_detailList || []
}
}
}
搞定~
更多推荐
已为社区贡献2条内容
所有评论(0)