我已经使用本指南实现了fuse.js: https://fusejs.io/ 和代码:
const Fuse = require("fuse.js");
var fuse = new Fuse(this.$store.state.vendorProducts, options);
var result = fuse.search(this.itemTitle);
结果变量包含搜索操作的所有结果。
我只想要结果的前 20 个结果。我可以对结果数组进行切片,但它太慢了,因为它加载了所有数据。
我如何限制搜索结果,例如限制前 20 项?
最佳答案
Fuse 搜索的搜索 SearchOpts
仅有参数 limit
,因此
const Fuse = require("fuse.js");
var fuse = new Fuse(this.$store.state.vendorProducts, options);
var result = fuse.search(this.itemTitle, {limit: 20});
通过查看源代码发现了此功能。
关于javascript - 限制fuse.js vue 中的搜索结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57646824/