本文主要是介绍vue2-computed,vue3+watch 前端实现列表搜索,结合filter+some+indexOf,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
vue2 computed实现
computed: {FBAAddressListComputed () {if (!this.fbaInput) return this.FBAAddressListconst lowerCaseInput = this.fbaInput.toLowerCase()return this.FBAAddressList.filter((item) => {return [item.fbaCode, item.zipCode, item.countryCode, item.state, item.city, item.address].some((field) => field && field.toLowerCase().indexOf(lowerCaseInput) !== -1)})},},
vue3 通过 watch 实现搜索
watch(fbaInput, newV => {if (fbaInput.value === '') {searchFbaList.value = FBAAddressList.valuereturn}const lowerCaseInput = fbaInput.value.toLowerCase()searchFbaList.value = FBAAddressList.value.filter(item => {return [item.fbaCode, item.zipCode, item.countryCode, item.state, item.city, item.address].some(field => field && field.toLowerCase().indexOf(lowerCaseInput) !== -1)})})
这篇关于vue2-computed,vue3+watch 前端实现列表搜索,结合filter+some+indexOf的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!