如何在Asyncstorage中设置多个值 [英] How do I set multiple values within Asyncstorage
本文介绍了如何在Asyncstorage中设置多个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Asyncstorge中设置多个值?因为我正在尝试设置token
和user_id
.这些是服务器响应值.
这就是响应的样子
How do I set multiple values within Asyncstorge?.Because I'm trying to set token
and user_id
.These are the server response values.
This is how response looks like
json
{ error: 0,
data: 'User registered Successfully',
userData:
{ pwd: 'lmlmlm',
phone_no: '9898989',
user_name: '',
status: 1,
date: 2018-10-24T07:12:20.656Z },
user_id: 60,
token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.' }
在响应本机之后,我在用户注册后就这样写了.
And in react native I've written like this after user registrtaion.
.then((response) => response.json())
.then((responseData) =>
{
console.log(responseData);
AsyncStorage.setItem('id_token', responseData.token),
AsyncStorage.setItem('user_id', responseData.user_id),
Actions.firstScreen();
});
在我的主页中,我以
AsyncStorage.getItem('id_token').then((usertoken) =>{
this.setState({'id_token' : usertoken});
console.log(usertoken);
})
AsyncStorage.getItem('user_id').then((uid) => {
this.setState({'user_id': uid});
console.log(uid);
})
但是我只得到令牌,uid
的控制台结果为null.但是当我控制台responseData
时,我在其中包含值.请帮助我
But I'm getting only the token , consoled result of uid
is getting as null.But when I consoled the responseData
I've values within it.Please help me
推荐答案
const items = [['k1', 'val1'], ['k2', 'val2']]
AsyncStorage.multiSet(items, () => {
//to do something
});
加油!
这篇关于如何在Asyncstorage中设置多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文