2 回答
![?](http://img1.sycdn.imooc.com/533e4c5600017c5b02010200-100-100.jpg)
TA贡献1812条经验 获得超5个赞
如果你使用了 react-navigation,试试这个来访问导航参数
componentDidMount() {
const { navigation } = this.props;
// console.log(navigation.state);
const hireId = navigation.state.params.hireId;
const ref = Firebase.firestore().collection('hires').doc(hireId);
ref.get().then((doc) => {
if (doc.exists) {
this.setState({
hire: doc.data(),
key: doc.id,
isLoading: false
});
} else {
console.log("No such document!");
}
});
}
并参考这个类似的问题 https://stackoverflow.com/questions/58279318/navigation-getparam-in-not-an-object/58280498#58280498
![?](http://img1.sycdn.imooc.com/54584f8f00019fc002200220-100-100.jpg)
TA贡献1906条经验 获得超3个赞
this.props.navigation.navigate('PastHireDetails', {
hireId: 12,
})
在上面的行中,您设置了一个名为hiringId 的导航参数,它是一个整数
const { navigation } = this.props
navigation.getParam('hireId')
navigation.getParam('hireId') 将返回一个整数值
但是在另一个脚本中,您可以通过以下方式将该整数转换为 JSON JSON.parse(navigation.getParam('hireId'))
这会给你一个错误
尝试删除 JSON.parse 因为它已经是您想要的整数
添加回答
举报