Skip to content

Commit 79e43a6

Browse files
committed
feat: fuse.js from 3.6.1 to 5.2.3 & 完善页面搜索相关代码
1 parent 9e61f30 commit 79e43a6

File tree

4 files changed

+18
-28
lines changed

4 files changed

+18
-28
lines changed

dependencies-cdn.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"element-ui": "^2.13.1",
2626
"faker": "^4.1.0",
2727
"flex.css": "^1.1.7",
28-
"fuse.js": "^3.4.6",
28+
"fuse.js": "^5.2.3",
2929
"github-markdown-css": "^4.0.0",
3030
"highlight.js": "^10.0.2",
3131
"hotkeys-js": "^3.7.3",

src/layout/header-aside/components/panel-search/index.vue

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -66,25 +66,10 @@ export default {
6666
value: e.fullTitle,
6767
...e
6868
})) : this.results
69-
}
70-
},
71-
methods: {
72-
/**
73-
* @description 过滤选项 这个方法在每次输入框的值发生变化时会触发
74-
*/
75-
querySearch (queryString, callback) {
76-
var pool = this.pool
77-
const results = this.query(queryString ? pool : [], queryString)
78-
this.results = results
79-
callback(results)
8069
},
81-
/**
82-
* @description 指定的数据源中根据指定的查询字符串过滤数据
83-
* @param {Object} pool 需要过滤的数据
84-
* @param {String} queryString 查询字符串
85-
*/
86-
query (pool, queryString) {
87-
return new Fuse(pool, {
70+
// 根据 pool 更新 fuse 实例
71+
fuse () {
72+
return new Fuse(this.pool, {
8873
shouldSort: true,
8974
tokenize: true,
9075
threshold: 0.6,
@@ -97,11 +82,16 @@ export default {
9782
'path'
9883
]
9984
})
100-
.search(queryString)
101-
.map(e => ({
102-
value: e.fullTitle,
103-
...e
104-
}))
85+
}
86+
},
87+
methods: {
88+
/**
89+
* @description 过滤选项 这个方法在每次输入框的值发生变化时会触发
90+
*/
91+
querySearch (queryString, callback) {
92+
const results = this.fuse.search(queryString).map(e => e.item)
93+
this.results = results
94+
callback(results)
10595
},
10696
/**
10797
* @description 聚焦输入框

0 commit comments

Comments
 (0)