首页 > 解决方案 > localStorage 在 TouchableOpacity 标签中不起作用

问题描述

我想同时使用localStorage并移动到另一个页面,但只移动工作,我无法获得价值

    const pressHandlerMapTest = () => {
        navigation.navigate("TestMapScreen");
      };
    return (
        <ImageBackground style={styles.background}>
            <View style={styles.tourWindow}>
                <TouchableOpacity underlayColor="red" 
                onPress={pressHandlerMapTest}
                onPressIn={() => {
                    localStorage.setItem('tour', 'others');
                  }}>
                    <Image source={require("../assets/royals.png")} ></Image>
                </TouchableOpacity>
                
                
            </View>
        
        </ImageBackground>

    );

标签: javascriptreact-native

解决方案


    const pressHandlerMapTest = () => {
        localStorage.setItem('tour', 'others');
        navigation.navigate("TestMapScreen");
      };
    return (
        <ImageBackground style={styles.background}>
            <View style={styles.tourWindow}>
                <TouchableOpacity underlayColor="red" 
                onPress={pressHandlerMapTest}
                >
                    <Image source={require("../assets/royals.png")} ></Image>
                </TouchableOpacity>
                
                
            </View>
        
        </ImageBackground>

    );

推荐阅读