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

问题: 组件内部执行传入的函数,无法获取函数的返回值。有其他途径么? #1865

Closed
xiaoshuimao opened this issue Jan 9, 2019 · 4 comments
Labels
question Further information is requested

Comments

@xiaoshuimao
Copy link

伪demo

page A

onBeforeSend(data)  {
  //data === 2  , true
  return false;
}
render() { 
  return <SendCode onBeforeSend={this.onBeforeSend} />
}

component SendCode

onSend() {
  const { onBeforeSend } = this.props;
  if(typoef onBeforeSend === 'function') {
     const data = onBeforeSend(2);  //data === undefined  , true
     // 知道是基于事件机制的, 所以拿不到。
     if(data) {
        // 发送验证码
     }

   }
}
render() {
   <View onClick={this.onSend}></View>
}

知道是基于事件机制的, 所以拿不到。有什么其他写法么?

@taro-bot
Copy link

taro-bot bot commented Jan 9, 2019

欢迎提交 Issue~

如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏

如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。

Good luck and happy coding~

@Chen-jj
Copy link
Contributor

Chen-jj commented Jan 9, 2019

将结果 setState,用 props 传。或者使用状态管理工具.

@dachaiyuan
Copy link

pageA
onBeforeSend(data, resolve) {
//data === 2 , true
resolve(false)
}
pageB
onSend() {
const { onBeforeSend } = this.props;
if(typoef onBeforeSend === 'function') {
// onBeforeSend(2,resolve); //data === undefined , true
// 知道是基于事件机制的, 所以拿不到。
new Promise( resolve => {
onBeforeSend(2,resolve);
} ).then( res => {
if(res){
// 发送验证码
}
} )
}
}

@yuche yuche added question Further information is requested resolved labels Apr 8, 2019
@taro-bot taro-bot bot added the to be closed label Apr 8, 2019
@taro-bot
Copy link

taro-bot bot commented Apr 8, 2019

Hello~

您的问题楼上已经提供了解决方案,如果没有更多的问题这个 issue 将在 15 天后被自动关闭。

如果您在这 15 天中更新更多信息自动关闭的流程会自动取消,如有其他问题也可以发起新的 Issue。

Good luck and happy coding~

@taro-bot taro-bot bot removed the to be closed label Apr 12, 2019
@taro-bot taro-bot bot closed this as completed Apr 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants