[英]How to define SecureLS in React.js to secure session details like JWT token?
I have gone through the git for SecureLS, but I find it difficult to define SecureLS in React.我已经浏览了 SecureLS 的 git,但我发现很难在 React 中定义 SecureLS。
var ls = new SecureLS({ encodingType: 'aes' })
How can I define like this in React.js class component?如何在 React.js class 组件中这样定义?
With React class components, you can create instances of class within componentDidMount
method in class components and store it in class variable使用 React class 组件,您可以在 class 组件的
componentDidMount
方法中创建 class 的实例并将其存储在 ZA2F2ED4F8EBC04ABCBDC4 变量中
class App extends React.Component {
componentDidMount() {
this.ls = new SecureLS({ encodingType: 'aes' })
}
}
Now you can use ls
anywhere in your class with this.ls
现在您可以通过 this.ls 在
this.ls
的任何地方使用ls
PS Do keep in mind context issues whenever you use this.ls
in class functions. PS在 class 函数中使用
this.ls
时,请记住上下文问题。 The this
inside class functions must refer to the class instance class函数里面的
this
必须引用class实例
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.