submitQuery:function(){ this.query = this.$refs.search.value.trim(); },
queryDate:function(list){ if (this.query === '') { return list } return list.filter((item)=>{ if(item.name.indexOf(this.query) != -1){ return item; } }) },
2、vue模糊搜索,原理都是一样的
筛选
onSubmit() { this.query = this.$refs.search.value.trim(); this.query1 = this.$refs.search2.value.trim(); }, queryDate:function(list){ if (this.query === '' && this.query1 === '') { return list } else if (this.query !== '' && this.query1 === '') { return list.filter(item => { if (item.name.indexOf(this.query) !== -1) { return item } }) } else if (this.query === '' && this.query1 !== '') { return list.filter(item => { if (item.mobile.indexOf(this.query1) !== -1) { return item } }) } else if (this.query !== '' && this.query1 !== '') { return list.filter(item => { if (item.name.indexOf(this.query) !== -1 && item.mobile.indexOf(this.query1) !== -1) { return item } }) } },
以上是“如何实现vue搜索和vue模糊搜索”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注创新互联行业资讯频道!