類似于Android原生中的SharedReference
,用于數(shù)據(jù)的持久化甸陌。
其存儲钠至,去除,刪除等動作均為耗時的異步操作溜腐。
JS中的異步處理
getItem
async _loadInitialState() {
var value = await AsyncStorage.getItem(STORAGE_KEY_ONE);
if (value != null) {
alert(value);
this._appendMessage('從存儲中獲取到數(shù)據(jù)為:' + value);
} else {
this._appendMessage('存儲中無數(shù)據(jù),初始化為空數(shù)據(jù)');
}
}
setItem
await AsyncStorage.setItem(STORAGE_KEY_ONE, '我是老王');
removeItem
await AsyncStorage.removeItem(STORAGE_KEY_ONE);