【发布时间】:2018-04-28 21:20:30
【问题描述】:
我知道有很多类似的线程,但由于我很难理解答案,我想我可以尝试使用我自己的代码,看看我是否能理解答案。
我只是将它设置为非常简单的测试。我有一个在启动应用程序时打开的索引文件。在索引中,我在 this.state 中有 testValue:
更新:
登录:
constructor(props){
super(props);
this.state={
credentials: {
username: "",
password:"",
}
}
this.navigate = this.props.navigation.navigate;
{...}
this.navigate("main", {
credentials: this.state.username,
});
In main:
constructor(props) {
super(props);
this.params = this.props.navigation.state.params;
this.navigate = this.props.navigation.navigate;
{...}
render() {
console.log(this.params.username);
【问题讨论】:
-
您没有在传递道具的位置显示代码。显示使用 TestIndex 的渲染方法
-
我没有通过道具。我怎么做?我只是在 this.state 中拥有它
-
如果你想让'testValue'成为一个道具,那么当你使用
Index中的TestIndex时,你必须做类似<TestIndex testValue={this.state.testValue}>的事情 -
我是通过按钮以某种方式传递它还是将其粘贴到某个地方?是的,我知道我听起来像个白痴,但我就是无法理解这一点。
标签: javascript reactjs react-native