vue3实现模糊搜索功能

一次性返回所有的数据,后端没有出搜索功能,自己撸了个搜索功能

   <a-input-search
        :style="{ width: '320px' }"
        placeholder="输入参数或名称"
        v-model="searchKey"
      />
数据
const allData = ref([])  //全部数据
搜索片段

利用 computed 实现,为了解决被筛选的字段的大小写问题,便使用toLowerCase()函数将所有字符串都转换成小写…然后利用 filter + includes 实现功能,具体代码片段如下

const fieldsData = computed(() => {
  let arr = allData.value.filter((iv: any) => {
    return searchKey.value
      ? iv.param.toLowerCase().includes(searchKey.value.toLowerCase()) ||
          iv.paramName.toLowerCase().includes(searchKey.value.toLowerCase())
      : allData.value
  })
  return arr
})

你可能感兴趣的:(Vue,3.0,javascript,前端,开发语言)