【问题标题】:Cannot read property of 'data'无法读取“数据”的属性
【发布时间】:2021-12-28 07:55:26
【问题描述】:

大家好,我尝试将反应本机中的数据从第一页传递到第二页,并尝试使用带有参数的控制台日志(route.params.data),但结果是无法读取“数据”的属性',。当我尝试使用此参数(路由)时,数据已成功传输到第二页,但是当我想调用 route.params.data 时,它的错误,这是我的完整代码https://snack.expo.dev/@ryankurniantara/navigator-flatlist

【问题讨论】:

  • 控制台日志来自哪里?你的意思是写 ({route}) 而不是 (route) 作为 index 的参数?

标签: javascript react-native


【解决方案1】:

在第 4 行,将 const index = (route) 更改为 const index = ({route})

import React from 'react'
import { StyleSheet, Text, View } from 'react-native'

const index = ({route}) => { // changed
    return (
        
            <View>
                <Text style={{fontSize: 21}}>
                    {route.params.data}
                </Text>
            </View>
        
    )
}

export default index

const styles = StyleSheet.create({})

【讨论】:

  • 好吧,我忘了在路由道具中使用 {}
猜你喜欢
  • 2019-06-22
  • 1970-01-01
  • 2013-02-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-13
  • 1970-01-01
  • 2022-01-18
相关资源
最近更新 更多