Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

object类型state更新为空{}时,页面数据不更新 #1058

Closed
nyrf opened this issue Nov 9, 2018 · 3 comments
Closed

object类型state更新为空{}时,页面数据不更新 #1058

nyrf opened this issue Nov 9, 2018 · 3 comments
Assignees

Comments

@nyrf
Copy link

nyrf commented Nov 9, 2018

问题描述
父组件state为object时,更新些object为{}空时,传给子组件,子组件不更新

复现步骤

[或者可以直接贴源代码,能贴文字就不要截图]

import { Component } from '@tarojs/taro'
import { View } from '@tarojs/components'

export default class Demo extends Component {

  render() {
    return (
      <View> demo id is : {this.props.product.name}</View>
    )
  }
}
import { Component } from '@tarojs/taro'
import { View } from '@tarojs/components'
import Demo from '../../components/demo'
class DemoPage extends Component {
  state = {
    product: {id: 1, name: 'demo'}
  }

  updateProduct () {
    this.setState({product: {}})
  }


  render() {
    return (
      <View>
        <Demo product={this.state.product} />
        <View onClick={this.updateProduct}>Update</View>
      </View>
    )
  }
}

期望行为
父组件中product更新为空{}后,子组件数据也跟着更新,把子组件内容重新初始化

报错信息

[这里请贴上你的完整报错截图或文字]

系统信息

  • 操作系统: osx 10.14
  • Taro 版本 1.1.1
  • Node.js 版本 v10.13.0
  • 报错平台 weapp
@nyrf
Copy link
Author

nyrf commented Nov 9, 2018

刚才发现,更新为空{},父组件页面也是不改变

@nyrf nyrf changed the title 组件props中的object类型数据更新为空{}时,子组件不更新 object类型state更新为空{}时,页面数据不更新 Nov 9, 2018
@Chen-jj Chen-jj self-assigned this Nov 12, 2018
@XiaogeTek
Copy link

关注

@luckyadam
Copy link
Member

luckyadam commented Nov 15, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants