zoukankan      html  css  js  c++  java
  • react传参

    通过params
            1.路由表中      
                  <Route path=' /sort/:id ' component={Sort}></Route>
               
            2.Link处        
                HTML方式
                     <Link to={ ' /sort/ ' + ' 2 ' } activeClassName='active'>XXXX</Link>     
               
              JS方式
                    this.props.router.push( '/sort/'+'2' )
               
            3.sort页面       
                   通过 this.props.params.id 就可以接受到传递过来的参数(id)
               
       方式 二:
             通过query
                    前提:必须由其他页面跳过来,参数才会被传递过来
        注:不需要配置路由表。路由表中的内容照常:<Route path='/sort' component={Sort}></Route>
            1.Link处      
             HTML方式
                <Link to={{ path : ' /sort ' , query : { name : 'sunny' }}}>
              
           JS方式
                this.props.router.push({ path : '/sort' ,query : { name: ' sunny'} })
     
            2.sort页面     
                  this.props.location.query.name
                                    
         方式 三:
            通过state
                同query差不多,只是属性不一样,而且state传的参数是加密的,query传的参数是公开的,在地址栏
            1.Link 处      
              HTML方式:
                    <Link to={{ pathname : ' /sort ' , state : { name : 'sunny' }}}> 
                                      
             JS方式:
                this.props.router.push({ pathname:'/sort',state:{name : 'sunny' } })
                                      
            2.sort页面       
                this.props.location.state.name
  • 相关阅读:
    Windows 2008 R2 安装 Windows phone 7 开发环境
    win 7,win2008 无法给新建用户完全权限
    基于Ajax的Asp.Net 简易在线聊天室
    phpwind ecshop 用户整合
    UVALive 3942 Remember the Word(字典树+DP)
    UVA 11732 strcmp() Anyone? (压缩版字典树)
    UVA 11992 Fast Matrix Operations(线段树:区间修改)
    hdu 2222 Keywords Search(AC自动机模版题)
    动态规划基础练习笔记
    递归与分治策略基础练习笔记
  • 原文地址:https://www.cnblogs.com/-swz/p/14313687.html
Copyright © 2011-2022 走看看