React

生命周期--存在期--componentWillReceiveProps

组件接收到新的props时调用,并将其作为参数nextProps使用,此时可以更改组件props及state。 之前做使用做过模拟选择实现二级联动效果.

componentWillReceiveProps (nextProps) {
        if (nextProps.[所传的props]) {
            this.setState({
               更新state
            });
        }
    }

react-router

1. Router组件中history属性值

**history属性,用来监听浏览器地址变化,将URL解析成一个地址对象{pathname: xxx, search:xxx}提供Router,Route中地址匹配。

var _createLocation = function _createLocation(historyState) {
  var key = historyState && historyState.key;

  return (0, _LocationUtils.createLocation)({
    pathname: window.location.pathname,
    search: window.location.search,
    hash: window.location.hash,
    state: key ? (0, _DOMStateStorage.readState)(key) : undefined
  }, undefined, key);
};
  • browserHistory
  • hashHistory
  • createMemoryHistory
browserHistory

其底层调用history API,最终url路径为/xxx/xxx/xx/xx,所以在使用打包工具的时候需要额外处理,不然会有可能访问到服务器端的路径,导致返回404。在使用webpack-dev-server 加上--history-api-fallback参数就可以了,参考

用户评论反馈组件(如:五星好评)

https://github.com/voronianski/react-star-rating-component

转载于:https://my.oschina.net/xinranzhou/blog/881195

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值