fuse如何使用

fuse强大的模糊查询插件官网

在这里插入图片描述

npm install fuse.js  
import Fuse from 'fuse.js'
created(){
    
    
//list为需要查询的数据
this.initFuse(list)
}
//初始化fuse
initFuse(list) {
    
    
	 this.fuse = new Fuse(list, {
    
    
		   shouldSort: true,
		   threshold: 0.4,
		   location: 0,
		   distance: 100,
		   maxPatternLength: 32,
		   minMatchCharLength: 1,
		   keys: [{
    
    
			 name: 'title',
			 weight: 0.7
		   }]
	  })
},
//需要查询的的时候调这个方法
//query为查询字符串
querySearch(query) {
    
    
	 if (query !== '') {
    
    
		this.options = this.fuse.search(query)    //fuse内置api   search
	  } else {
    
    
		this.options = []
	  }
}

猜你喜欢

转载自blog.csdn.net/weixin_44162077/article/details/129499412