js implements fuzzy search

1. Fuzzy search function

//list 是已有的数据,search 是模糊搜索的关键字
export const fuzzySearch = (list,search)=>{
    
    
  let data = [];
  if(list.length != 0 && search){
    
    
    let str = `\S*${
      
      search}\S*`;
    let reg = new RegExp(str,'i');//不区分大小写
    list.map(item => {
    
    
      if(reg.test(item)){
    
    
        data.push(item);
      }
    })
  }
  return data;
}

2. After importing in the vue file, use it directly

fuzzySearch(list,search)

Reference link:
1. https://blog.csdn.net/weixin_43299180/article/details/115176745
2. https://blog.csdn.net/qq_30607437/article/details/108389729

Learn together and make progress together!

Guess you like

Origin blog.csdn.net/qq_33235680/article/details/125442736