Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我通过 npm 安装了 Mousetrap 并一直试图让 Mousetrap.bindGlobal 工作,但这是它给我的错误
Uncaught TypeError: mousetrap__WEBPACK_IMPORTED_MODULE_13__.bindGlobal is not a function
这没有意义,因为当我在 jsx 文件中导入 mousetrap 时,vscode 显示该命令有效。对此的任何帮助都会很有用。
bindGlobal在 TypeScript 定义中,但不在 NPM 包中。这是一个扩展。
bindGlobal
您可以在此处查看文档。您可以手动添加扩展,也可以使用 NPM/Yarn 添加。我找不到任何官方软件包,但这个似乎工作正常。
$ npm i mousetrap-global-bind $ yarn add mousetrap-global-bind
为了让它工作,你需要添加 Mousetrap,然后是扩展。
import mousetrap from 'mousetrap'; import 'mousetrap-global-bind';