You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native Expo中AsyncStorage数据无法在LocalStorage显示问题咨询

问题解答

代码正确性判断

你的代码逻辑是正确的,没有语法错误,AsyncStorage.setItem的调用方式符合官方规范,try/catch也正确处理了存储异常。点击按钮后应该能成功存储hasTermsAndPolicy: 'true'这个键值对。

为什么DevTools的LocalStorage看不到数据

@react-native-async-storage/async-storage 在Expo Web环境中,并不是存储在LocalStorage里,而是存在IndexedDB中。你需要在Chrome DevTools的Application面板里,找到IndexedDB -> RCTAsyncLocalStorage -> keyvaluepairs,就能看到你存储的键值对了。

验证数据是否存储成功的额外方法

你可以在handleAgree方法里添加读取逻辑,直接确认数据是否真的存入:

const handleAgree = async () => {
  try {
    await AsyncStorage.setItem('hasTermsAndPolicy', 'true');
    // 添加读取验证
    const storedValue = await AsyncStorage.getItem('hasTermsAndPolicy');
    console.log('存储的值:', storedValue);
    setModalVisible(false);
    navigation.navigate("OnboardingPage/OnboardingPage");
  } catch (error) {
    console.error("Failed to save the Terms and Policy status:", error);
  }
};

内容的提问来源于stack exchange,提问作者Ujang Aripin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 05:21:15