我试图通过fuse.js将模糊搜索库添加到我的项目中。我包括以下几行,我得到一个构造函数错误,我试图重新安装保险丝,但我想知道错误可能在哪里。
// TypeError: Fuse is not a constructor
var Fuse = require('fuse');
var options = { // list of options that need to be provided to fuse.js for search to occur
shouldSort: true,
threshold: 0.6,
location: 0,
distance: 100,
maxPatternLength: 32,
minMatchCharLength: 1,
keys: [
"title", // the keys that are searched
"description"
]
};
var fuse = new Fuse(posts, options); // "list" is the item array
var result = fuse.search(searchOptions.keywords); // search is conducted and result should be all matching JSON objects
您将fuse.js模块与fuse模块混淆,后者是completely different project。您可以通过查看Fuse.js网站的"Install"部分来了解情况。
要解决此问题,请运行npm install --save fuse.js
并修复具有以下要求的行:
var Fuse = require('fuse.js');
你在使用打字稿吗?
您需要先安装库:运行npm install --save fuse.js
。
然后在要使用库的文件顶部导入库:import * as Fuse from 'fuse.js'