【发布时间】:2016-05-31 10:13:54
【问题描述】:
我正在使用 React Native 的 AsyncStorage 来存储授权令牌,当需要用于新的 http 请求时将返回该令牌。虽然我可以成功存储它并控制台记录它,但我在返回值时遇到了一些麻烦。我想在另一个窗口中调用它,以
的方式 var x= LocalDb.getAcessToken();
console.log(x);
但它不会起作用。
LocalDb.getAccessToken();
另一方面,这在 getAcessToken() 中包含 console.log 时有效
exports.storeToken=function(token){
AsyncStorage.setItem('access_token', token);
}
^^^^这个函数成功保存了token
exports.getAccessToken=function(){
AsyncStorage.getItem('access_token')
.then((value) => {
if(value) {
console.log(value);
**//I want to return the value here, to use in another function**
}
})
.done();
}
使用 return(value) 时无法返回值。如何从 Promise 中返回值?
【问题讨论】:
标签: authentication react-native token es6-promise asyncstorage