How do I use pure javascript library, hashids.js o

2019-09-04 00:44发布

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条回答
Bombasti
2楼-- · 2019-09-04 01:22

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);
查看更多
登录 后发表回答