Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我已经浏览了 SecureLS 的 git,但我发现很难在 React 中定义 SecureLS。
var ls = new SecureLS({ encodingType: 'aes' })
如何在 React.js 类组件中这样定义?
使用 React 类组件,您可以componentDidMount在类组件中的方法内创建类的实例并将其存储在类变量中
componentDidMount
class App extends React.Component { componentDidMount() { this.ls = new SecureLS({ encodingType: 'aes' }) } }
现在您可以ls在课堂上的任何地方使用this.ls
ls
this.ls
PSthis.ls每当您在类函数中使用时,请记住上下文问题。内部this类函数必须引用类实例
this