在React Native中如何在会话中存储值?

时间:2017-03-06 14:20:19

标签: react-native react-native-android react-native-ios

在React Native中如何在会话中存储值?

我需要在会话中存储登录详细信息(用户名,密码)。

你能否提出任何想法。

1 个答案:

答案 0 :(得分:17)

使用AsyncStorage

示例:

保存:

AsyncStorage.multiSet([
    ["email", userInfo.email],
    ["password", userInfo.password]
])

删除:

let keys = ['email', 'password'];
AsyncStorage.multiRemove(keys, (err) => {
    console.log('Local storage user info removed!');
});

获取:

AsyncStorage.multiGet(['email', 'password']).then((data) => {
    let email = data[0][1];
    let password = data[1][1];

    if (email !== null)
        //Your logic
});

PDTA:,因为 Raheel 提及password应为encrypted