问题
I tried importing the library directly
import * as hash from '../../../../node_modules/hashids';
and tried this code
let id = hash.encode(this.studentDocument.student_id_number); console.log(id);
But it throws this error, sad.
_node_modules_hashids__WEBPACK_IMPORTED_MODULE_2__.encode is not a function
I even tried this
declare var hash:any;
But it throws this error
hash is not defined
Any tip would be greatly appreciated! (a cont. of this post)
回答1:
You need to create a new instance of the hashids object.
import * as hash from 'hashids';
const hashids = new hash();
const id = hashids.encode(348029348);
console.log(id);
来源:https://stackoverflow.com/questions/52252611/how-do-i-use-pure-javascript-library-hashids-js-on-angular