为了账号安全,请及时绑定邮箱和手机立即绑定

为什么react里只用componentDidMount()获取数据render给我执行了4次

为什么react里只用componentDidMount()获取数据render给我执行了4次

Cats萌萌 2019-03-05 08:50:40
@connect(({ editnews,global, loading }) => ({  global,   editnews,   loading: loading.models.editnews,   timeLoading: loading.effects['editnews/getCollections'], }))componentDidMount() {     message.warning("请修改参数点击搜索,筛选展示数据!",10)     const { dispatch} = this.props;     dispatch({      type: 'editnews/getCollections',       payload: {}     });   }render() {    const {       editnews: { data, data: { pagination }, collections },       loading,       timeLoading,     } = this.props;     console.log(pagination)
查看完整描述

2 回答

?
jeck猫

TA贡献1909条经验 获得超7个赞

在一个组件中 stateprops改变 都会执行render方法,可能是因为你的其他数据发生了改变;
如果不想执行render方法,可以在 shouldComponentUpdate 方法中进行判断,return false就可以阻止render,这也是react官方推荐的解决方案。

查看完整回答
反对 回复 2019-03-05
  • 2 回答
  • 0 关注
  • 5980 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信