提交 3c365f1a authored 作者: vipcxj's avatar vipcxj

修复AsyncStorage的错误用法

上级 5de17f15
......@@ -2,52 +2,52 @@
* Created by yaohx_169 on 2017/6/8.
*/
import { cookie } from './config';
import { AsyncStorage } from 'react-native';
import store from './store';
export async function getToken() {
return AsyncStorage.getItem(cookie.token);
return store.getItem(cookie.token);
}
export async function setToken(token) {
return AsyncStorage.setItem(cookie.token, token);
return store.setItem(cookie.token, token);
}
export async function delToken() {
return AsyncStorage.removeItem(cookie.token);
return store.removeItem(cookie.token);
}
export async function getUser() {
return {
id: await AsyncStorage.getItem(cookie.userId),
name: await AsyncStorage.getItem(cookie.userName),
id: await store.getItem(cookie.userId),
name: await store.getItem(cookie.userName),
};
}
export async function setUser(id, name) {
await AsyncStorage.setItem(cookie.userId, id);
await AsyncStorage.setItem(cookie.userName, name);
await store.setItem(cookie.userId, id);
await store.setItem(cookie.userName, name);
}
export async function delUser() {
await AsyncStorage.removeItem(cookie.userId);
await AsyncStorage.removeItem(cookie.userName);
await store.removeItem(cookie.userId);
await store.removeItem(cookie.userName);
}
export async function getDomain() {
return {
name: await AsyncStorage.getItem(cookie.domainName),
path: await AsyncStorage.getItem(cookie.domainPath),
name: await store.getItem(cookie.domainName),
path: await store.getItem(cookie.domainPath),
};
}
export async function setDomain(name, path) {
await AsyncStorage.setItem(cookie.domainName, name);
await AsyncStorage.setItem(cookie.domainPath, path);
await store.setItem(cookie.domainName, name);
await store.setItem(cookie.domainPath, path);
}
export async function delDomain() {
await AsyncStorage.removeItem(cookie.domainName);
await AsyncStorage.removeItem(cookie.domainPath);
await store.removeItem(cookie.domainName);
await store.removeItem(cookie.domainPath);
}
export async function isAuthed() {
......
import { AsyncStorage } from 'react-native';
export default {
async getItem(key) {
const item = await AsyncStorage.getItem(key);
if (item) {
return JSON.parse(item);
} else {
return null;
}
},
async setItem(key, value) {
const item = JSON.stringify(value);
return await AsyncStorage.setItem(key, item);
},
async delItem(key) {
return AsyncStorage.removeItem(key);
},
}
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论