2

我试图通过 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
4

2 回答 2

7

您将fuse.js模块与fuse模块混淆了,这是一个完全不同的项目。您可以通过查看 Fuse.js 网站的“安装”部分来了解情况。

要解决此问题,请运行npm install --save fuse.js并修复以下要求的行:

var Fuse = require('fuse.js');
于 2017-04-20T22:48:54.480 回答
-1

你在使用打字稿吗?

您需要先安装库:运行npm install --save fuse.js.

然后在您要使用该库的文件之上导入该库: import * as Fuse from 'fuse.js'

于 2018-11-07T14:58:31.950 回答