如何使用 ReactXP 存储 API?



我是ReactXP新手,我正在尝试使用MicrosoftReactXP框架创建一个小应用程序。我想将键值对保存在本地存储中。Microsoft提供了一个名为 Storage 的 API https://microsoft.github.io/reactxp/docs/apis/storage.html https://github.com/Microsoft/reactxp/blob/master/src/web/Storage.ts

我正在尝试将其用作

onLoginPressed(){
const user = new User(this.state.userEmail, this.state.password);
RestClient.login(user).then(success => {
alert(success.message);
Storage.setItem('userEmail', success.userInfo.userEmail);
}).catch(error => {
alert('Error in login');
});
}

但它显示错误

ERROR in [at-loader] ./src/Login.tsx:102:21
TS2339: Property 'setItem' does not exist on type '{ new (): Storage; prototype: Storage; }'.

由于文档不佳,我无法使用它。有人可以帮助我吗?

我找到了如下解决方案

onLoginPressed(){
const user = new User(this.state.userEmail, this.state.password);
RestClient.login(user).then(success => {
alert(success.message);
RX.Storage.setItem('userEmail', success.userInfo.userEmail);
}).catch(error => {
alert('Error in login');
});
}

您可以按如下方式获得它:

RX.Storage.getItem('userEmail').then(success => {
this.setState({
userEmail: success
});
});

最新更新