React-native之持久化保存----AsyncStorage

这篇写的全,传送门:
http://www.cnblogs.com/liuShanPei1024/p/5783197.html?utm_source=tuicool&utm_medium=referral

数组的写法:

退出id

AsyncStorage.removeItem('id',  (error)=> {
            if (error) {
                console.log('id'+error);
            } else {
                console.log('id'+'成功');
            }
        });

记录id

var Arr= [telephone,possWord];
                    AsyncStorage.setItem('word', JSON.stringify(Arr), (error)=>{
                        if (error) {
                            console.log(error);
                        } else {
                            const { navigator } = this.props;
                            this.props.getPrams(responseData.data);
                            if(navigator){
                                navigator.pop();
                            }
                        }
                    });

读取id

AsyncStorage.getItem('id').then((value) => {
            if (value==null){
            }else{
                const jsonValue = JSON.parse(value);
                this.setState({
                    token:jsonValue[0],
                    id:jsonValue[1],
                    nickname:jsonValue[2],
                    image:jsonValue[3]
                });
                console.log(this.state.token);
            }
        });

你可能感兴趣的:(React-native之持久化保存----AsyncStorage)