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;
        }
    }    

 

posted @ 2022-07-29 13:47  叶乘风  阅读(177)  评论(0编辑  收藏  举报