简体   繁体   English

crypto-js 如何隐藏类方法?

[英]how crypto-js hide the class method?

Start With This从这个开始

import crypto from 'crypto-js'
global.crypto = crypto

When I Access crypto from the browser Console I got the following error当我从浏览器控制台访问加密时,出现以下错误

crypto['AES'].encrypt('MyString', 'pass').toString() // Uncaught TypeError: Cannot read property 'encrypt' of undefined(…)

but when I access it from Node it works -_-但是当我从 Node 访问它时它可以工作-_-

crypto['AES'].encrypt('MyString','pass').toString() // Encrypted String

How Crypto JS do this? Crypto JS 如何做到这一点? can't directly access from the browser, but accessible in node?不能直接从浏览器访问,但可以在节点中访问?

I believe your issue is that 'crypto' is reserved internally by the window object.我相信您的问题是“加密”是由 window 对象在内部保留的。 Try importing under another name.尝试以其他名称导入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM