this.props 的神奇用法(路由传参)
2020-03-28 本文已影响0人
IFu的简书
问题描述:
移动端培训项目,之前大多用GET请求。最近接到一个功能需求,后台给我做了五个POST接口,一瞬间有点凌乱。
由于所有接口都是POST的请求,每个接口的请求参数大约都有四五个,而且是来自不同接口的返回值以及自定义值。而react的数据向来是存在reducer中的,所以造成了页面一刷新,这些由上一个接口返回过来的,对应请求参数数据就获取不到了。结果当然是“查询不到”啦~
本文侧重汇总 : ①this.props的用法;②react常用的路由传参方法。
知识一:
传递数据: this.props.history.push({pathname:'/xxxx',state:{data:data}})
取数据: let ltEnrollInfo = this.props.location.state.ltEnrollInfo;



(有时间再细理this.props)
知识二:
汇总一下常用的三种路由传参方式:
1、params传参(刷新页面后参数不消失,参数会在地址栏显示)

1、params传参(多个动态参数)

2、query传参(刷新页面后参数消失)

3、state传参( 刷新页面后参数不消失,state传的参数是加密的,比query传参好用)
