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

state和prop重名 state会覆盖props #109

Closed
kdong007 opened this issue Jun 13, 2018 · 4 comments
Closed

state和prop重名 state会覆盖props #109

kdong007 opened this issue Jun 13, 2018 · 4 comments
Labels
enhancement New feature or request

Comments

@kdong007
Copy link
Contributor

class Test extends Taro.Component{
    state={
      val:999
    }
    render(){
        return <View>{this.props.val}</View>
    }
}

模拟器上显示为999

如果把Test的val改成val2就显示正常

state = {
    val2:999
}
@yuche
Copy link
Contributor

yuche commented Jun 13, 2018

的确有这个问题,由于我们是自己做的组件化方案,不管 props 还是 state都会打入到小程序 Pagedata 中。我们暂时准备做一个 ESLint 规则,先提示开发者不要这么写。

前些日子微信小程序更新了新的能力,我们应该会基于微信小程序的组件化重构 Taro 的组件化方案。到时这个问题应该就不存在了。很多限制也不会存在(例如在自定义组件里写 this.props.children,通过 props 传递 JSX)。

@nyrf
Copy link

nyrf commented Oct 22, 2018

现在能用一样的名字不?

@kid1412621
Copy link

貌似官网都没相关信息

@yuche
Copy link
Contributor

yuche commented Mar 19, 2019

貌似官网都没相关信息

eslint 和编译应该都会报错的的

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

No branches or pull requests

4 participants