如何在角度上使用纯javascript库,hashids.js?

问题描述 投票:0回答:1

我试着直接导入库

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的续)

javascript angular typescript hashids
1个回答
2
投票

您需要创建一个hashids对象的新实例。

import * as hash from 'hashids';

const hashids = new hash();
const id = hashids.encode(348029348);
console.log(id);
© www.soinside.com 2019 - 2024. All rights reserved.