我正在尝试通过fuse.js将模糊搜索库添加到我的项目中。我包含了以下几行代码,我得到了一个构造函数错误,我试图重新安装fuse,但我想知道错误可能在哪里。
// 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发布于 2017-04-21 06:48:54
您混淆了模块和模块,后者是一个completely different project。您可以通过查看Fuse.js网站的"Install"部分看到这一点。
要解决此问题,请运行npm install --save fuse.js并修复包含以下要求的行:
var Fuse = require('fuse.js');发布于 2018-11-07 22:58:32
你在使用typescript吗?
您需要首先安装库:运行npm install --save fuse.js。
然后,在要使用库的文件顶部导入库:import * as Fuse from 'fuse.js'
https://stackoverflow.com/questions/43531090
复制相似问题