我试着直接导入库
import * as hash from '../../../../node_modules/hashids';
并尝试了这段代码
let id = hash.encode(this.studentDocument.student_id_number); console.log(id);
但它抛出这个错误,很难过。
_node_modules_hashids__WEBPACK_IMPORTED_MODULE_2__.encode is not a function
我甚至试过这个
declare var hash:any;
但它抛出了这个错误
hash is not defined
任何提示将不胜感激! (这个post的续)
您需要创建一个hashids对象的新实例。
import * as hash from 'hashids';
const hashids = new hash();
const id = hashids.encode(348029348);
console.log(id);