-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
解构语法-默认值 #1630
Comments
欢迎提交 Issue~ 如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏 如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。 Good luck and happy coding~ |
暂时通过使用 defaultProps 解决 |
// 原来
success(res) {
...
}
// 写成这样:
success: (res) => {
..
}
// 或者在一开始的时候
const { onLoginSuccess } = this.props
onLoginSuccess() 这样你就不用写 that 了,当你写 |
@patchBig 你子组件定义了 defaultProps,父组件不传 title,不就使用了 defaultProps 中定义的 title 值了么。 |
结构语法里面,为null的值不会使用默认值,undefined才会使用默认值,这是正常的吧 |
并没有。。。直接就是 null |
@zhouweiming 父组件不传的话,在 react 中是 undefined,他这样写应该正常取到默认值。 但小程序中,props 通过小程序组件化的 properties 实现,父组件不传时参数默认值为 null,所以他这种解构写法取不到默认值。 暂时推荐使用 defaultProps 解决。 |
@patchBig 贴一下父子组件可复现代码。 感觉你是写了 defaultProps 的同时,又使用了解构赋予默认值的写法。 |
子组件
|
父组件
|
那你就只能这样了:
或者你写 async/await,不用回调式的 API。 |
这样可以 👍 不过为啥用 that 不好使呢?之前的 that 和 this 不是一个东西吗?🐶 |
因为数据绑定的延时性?上面的 console 应该就说明这个问题了,对吗 |
defaultProps 只能酱写?就没问题。。。
|
@patchBig 额,是的,建议先看看 ES6 class 中 static 属性的文档 |
@patchBig 因为编译器要求你一定要写 this.props.onXX 或者从 this.props 结构出来的函数才能正确编译。 |
好的 非常感谢
非常感谢。。。 |
关于这点的话,文档中貌似没注意到有这一条。。。(不过以后注意吧) |
The text was updated successfully, but these errors were encountered: