react setstate改变值后 组件不更新

async componentDidMount () {
    let res = await getAO(this.props.match.params.id)
    this.props.form.setFieldsValue({
      name: res.name,
      contactName: res.extra.contactName,
      contactMobile: res.extra.contactMobile, 
      industryId: {key: res.industryId, label: 'id'},
      pcUrl: res.extra.pcUrl,
      wapUrl: res.extra.wapUrl,
      detailAddress: res.extra.detailAddress,
      contractPeriodAt: res.extra.contractPeriodAt,
      contractPeriodNumber: res.extra.contractPeriodNumber,
      // salesArea: res.extra.salesArea,
      tin: res.tin,
      bankAccount: res.extra.bankAccount,
      bankAccountName: res.extra.bankAccountName,
      bankBranchName: res.extra.bankBranchName,
      bankName: res.extra.bankName
    })

    this.state.initAddress.provinceId = Number(res.extra.provinceId)
    this.state.initAddress.cityId = Number(res.extra.cityId)
    this.state.initAddress.regionId = Number(res.extra.regionId)
    this.state.initAddress.streetId = Number(res.extra.streetId)

    this.setState({
      initAddress: {
        provinceId: Number(res.extra.provinceId),
        cityId: Number(res.extra.provinceId),
        regionId: Number(res.extra.provinceId),
        streetId: Number(res.extra.provinceId)
      }
    }, function () {
      console.log('updata',this.state)
    })
  }

省市区组件一直取得是默认值~
怎么能解决这个问题~~~

阅读 3.8k
3 个回答

你的initAddress也是表单项吗?如果是,也需要使用form.setFieldsValue去更新它。

this.props是什么操作 你要是想改变父组件得值的话 得在父组件中改变数据 传参传过来方法 通过方法去改父组件得数据啊https://www.jianshu.com/p/fce150c18343 还有您这个代码规范 我实在是不敢恭维

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题