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 = []
}
}