其他分享
首页 > 其他分享> > 2022-07-29 react-native 页面传参以及接受参数

2022-07-29 react-native 页面传参以及接受参数

作者:互联网

函数组件:

发送:
const B = ({ navigation}) => { const toDetail = () => {

     navigation.navigate('detail', { id: 666 });
  }
}
接收:
const B = ({ navigation, route }) => {
    useEffect(() => {
        console.log(route.params.id);
    }, []);
}

 类组件:

// 发送:

 

    onPress = { () => { this.navigation.navigate('Device', { id: 'sds', name: 'Qli' }) }}
 // 接收:     export default class Device extends Component         componentDidMount() {             let id = this.props.navigation.state.params.id;          let name = this.props.navigation.state.params.name;         }     }    

 

标签:传参,const,07,29,params,props,navigation,id,name
来源: https://www.cnblogs.com/iuniko/p/16532021.html