欧美亚洲中文,在线国自产视频,欧洲一区在线观看视频,亚洲综合中文字幕在线观看

      1. <dfn id="rfwes"></dfn>
          <object id="rfwes"></object>
        1. 站長(zhǎng)資訊網(wǎng)
          最全最豐富的資訊網(wǎng)站

          react跳轉(zhuǎn)傳值怎么實(shí)現(xiàn)

          react跳轉(zhuǎn)傳值的實(shí)現(xiàn)方法:1、通過(guò)“history.push”或“NavLink”實(shí)現(xiàn)頁(yè)面跳轉(zhuǎn);2、通過(guò)“this.props.history.push({pathname: 'login',query: {id: …,name: …}})this.props.history.push('modify')”實(shí)現(xiàn)傳值即可。

          react跳轉(zhuǎn)傳值怎么實(shí)現(xiàn)

          本教程操作環(huán)境:Windows10系統(tǒng)、react18.0.0版、Dell G3電腦。

          react跳轉(zhuǎn)傳值怎么實(shí)現(xiàn)?

          react項(xiàng)目頁(yè)面跳轉(zhuǎn)/傳值

          一、跳轉(zhuǎn)

          1、history.push 跳轉(zhuǎn)

          • 引用 withRouter
          • 導(dǎo)出組件時(shí)使用

          import { withRouter } from 'react-router-dom';  class Header extends React.Component {  } export default withRouter(Header);
          登錄后復(fù)制

          2、NavLink跳轉(zhuǎn)

          import { NavLink } from "react-router-dom"; <NavLink to="/modify">修改密碼</NavLink>
          登錄后復(fù)制

          二、傳值

          1、路由傳值 query/params

          this.props.history.push({     pathname: 'login',     query: {         id: 3231,         name: 3231     }})this.props.history.push('modify')
          登錄后復(fù)制

          2、路由傳值獲取參數(shù)

          this.props.match.query.id // 3231 this.props.match.params.name // 3231
          登錄后復(fù)制

          react跳轉(zhuǎn)傳值怎么實(shí)現(xiàn)

          3、props傳值

          父組件:

          state = {     collapsed: false,};render() {     const { collapsed } = this.state;     return (         <Slider collapsed={collapsed}/>     )}
          登錄后復(fù)制

          子組件:

          componentDidMount(){     // console.log(this.props)     const { pathname } = this.props.location    if( pathname ) {         this.setState({                            selectedKeys:this.props.location.pathname        })     }}
          登錄后復(fù)制

          console.log(this.props)
          react跳轉(zhuǎn)傳值怎么實(shí)現(xiàn)

          推薦學(xué)習(xí):《react視頻教程》

          贊(0)
          分享到: 更多 (0)
          網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)