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

同一个事件处理函数在同一个组件上不能多次bind #432

Closed
vimcaw opened this issue Aug 7, 2018 · 3 comments
Closed

同一个事件处理函数在同一个组件上不能多次bind #432

vimcaw opened this issue Aug 7, 2018 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@vimcaw
Copy link
Contributor

vimcaw commented Aug 7, 2018

问题描述
同一个事件处理函数在同一个组件上不能多次bind,只能生成同一个函数。

复现步骤

<ActionBar
  onAddToCart={this.showSku.bind(undefined, 'addToCart')}
  onPurchase={this.showSku.bind(undefined, 'purchase')}
/>

期望行为
生成两个不同的函数,每个的参数都不同。

报错信息
无报错,但是与期望行为不一致,最终只会生成同一个参数一样的函数,后面的bind会把前面的覆盖掉, 最终生成的函数为最后一次bind的结果。

即对于上述代码:无论触发onAddToCart事件还是onPurchase事件,showSku函数接收到的参数始终是purchase

系统信息

  • 操作系统: Windows 10
  • Taro 版本 v1.0.0.beta.7
  • Node.js 版本 v8.11.2

补充信息

@Simbachen
Copy link
Contributor

当前版本同一个事件处理函数在同一个组件上多次绑定,如果有用到xx.bind(this, args)的方式来传参,则参数会冲突。
建议暂时先通过1、在组件里调用的时候才传参,或2、定义两个方法showSkuA,showSkuB 来规避这个问题

@luckyadam luckyadam added the enhancement New feature or request label Aug 13, 2018
@stale
Copy link

stale bot commented Oct 24, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

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

5 participants