Taro: Button组件onGetUserInfo未执行

Created on 2 Aug 2018  ·  5Comments  ·  Source: NervJS/taro

问题描述
在获取用户信息时,官方文档给出
<button open-type="getUserInfo" lang="zh_CN" bindgetuserinfo="onGotUserInfo">获取用户信息</button> ...... onGotUserInfo: function(e) { console.log(e.detail.errMsg) console.log(e.detail.userInfo) console.log(e.detail.rawData) }

转成Taro框架下:
<button open-type="getUserInfo" lang="zh_CN" onGetUserInfo={this.onGotUserInfo}>获取用户信息</button> ...... onGotUserInfo (e) { console.log(e.detail.errMsg) console.log(e.detail.userInfo) console.log(e.detail.rawData) }
未执行

换官方回调参数:
<button open-type="getUserInfo" lang="zh_CN" bindgetuserinfo={onGotUserInfo}>获取用户信息</button>
输出以下警告:

Do not have onGotUserInfo handler in current page: pages/index/index. Please make sure that onGotUserInfo handler has been defined in pages/index/index, or pages/index/index has been added into app.json

能想的办法都想过了,使用 bindgetuserinfo + 其他函数
<button open-type="getUserInfo" lang="zh_CN" bindgetuserinfo={showLocation}>获取用户信息</button> ...... showLocation() { console.log('oye') }
正常输出

But! 奇怪的在后面:
<button open-type="getUserInfo" lang="zh_CN" bindgetuserinfo={showLocations}>获取用户信息</button> ...... // 地图上显示当前位置 showLocations() { console.log('oye') }

又会提示:

Do not have showLocations handler in current page: pages/index/index. Please make sure that showLocations handler has been defined in pages/index/index, or pages/index/index has been added into app.json

代码截图如下
https://github.com/JerrySir/An_client/blob/master/src/pages/index/index.js#L118

Most helpful comment

<Button id='login-btn' openType="getUserInfo" lang="zh_CN" onGetUserInfo={onGotUserInfo} type='primary' >微信用户快速登录</Button>

All 5 comments

解决方法:
button改为Button
open-type改为openType

<Button id='login-btn' openType="getUserInfo" lang="zh_CN" onGetUserInfo={onGotUserInfo} type='primary' >微信用户快速登录</Button>

解决了 谢谢

老哥,这段应该写到文档里啊

<Button id='login-btn' openType="getUserInfo" lang="zh_CN" onGetUserInfo={onGotUserInfo} type='primary' >微信用户快速登录</Button>

文档里确实没找到

Was this page helpful?
0 / 5 - 0 ratings