在https://www.npmjs.com/package/hashids上运行教程中的代码
<script type="text/javascript" src="js/hashids.min.js"></script>
<script type="text/javascript">
var hashids = new Hashids();
console.log(hashids.encode(1));
</script>获取错误:Uncaught TypeError: Hashids is not a constructor.
我在一个没有模块的香草js应用程序中运行这个程序。只有html和js文件。如果我使用reqire(hasids),那么它会弹出错误:require is not defined。我需要在我用普通浏览器javascript编码的应用程序上运行这个程序。请帮我处理这个。谢谢!
发布于 2019-11-30 03:28:48
该模块的网络信息是不正确的。当您导入脚本时,您必须使用
var hashids = new Hashids.default();您可能会想记录一个Github问题;这显然是误导的,因为他们明确地告诉您执行代码所做的事情。
https://stackoverflow.com/questions/59112812
复制相似问题