You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@connect((state,props)=>({play: getPlayList(state,props.match.params.id)}),dispatch=>({playlist: bindActionCreators(playlist,dispatch)}))classPlayListextendsComponent{componentDidMount(){const{params: { id }}=this.$routerconst{ play, playlist }=this.propsif(!play||!play.data){playlist({ id })}}render(){return(<View>1111</View>)}}
取数据
const{play: { data ={}}}=this.props
不能通过props获取到id只能像下面这样写了,比较麻烦,特别是接口多的时候
@connect((state,props)=>({play: state.player// player redux的名字}),dispatch=>({playlist: bindActionCreators(playlist,dispatch)}))classPlayListextendsComponent{componentDidMount(){const{params: { id }}=this.$routerconst{ play, playlist }=this.propsif(!play[id]||!play[id].data){playlist({ id })}}render(){return(<View>1111</View>)}}
问题描述
如路由是 /play/subject/index?id=1
在redux里的 @connect 这里想获取 id=1 现在是获取不到的
这样做,是为了,把每一个id存一个KEY,方便缓存数据。现在取不到了,就很麻烦。
取数据
不能通过props获取到id只能像下面这样写了,比较麻烦,特别是接口多的时候
方法 getPlayerList
然后取数据要通过 this.$router.params 获取 id
期望行为
[希望props可以获取路由上参数]
报错信息
[无]
系统信息
The text was updated successfully, but these errors were encountered: