componentDidMount(){
console.log("get")
AsyncStorage.getItem('token')
.then((res)=>{
console.log(res)
})
}我有componentDidMount和console.log和AsyncStorage.getItem函数,我想在得到令牌值之后进行axios调用。
但问题是,AsyncStorage.getItem没有工作,get //console.log('get')打印为日志,不带res。
有什么帮助吗?如何获得价值?我做错什么了吗?
发布于 2018-09-10 19:58:49
你可以这样做。
componentDidMount(){
this.onGetToken();
}
onGetToken = async () => {
try {
const token = await AsyncStorage.getItem('token');
console.log("get")
// call api using axios with token value
} catch(e => console.info('error for getting token', e))
}发布于 2018-09-10 20:40:45
尝试重新启动应用程序,asyncStorage就会正常运行。
https://stackoverflow.com/questions/52264481
复制相似问题