能调起授权的弹窗,却没办法触发回调,找来找去也没在文档里找到这个回调的名字具体是什么
function Main() {
const handleGetUserInfo = r => {
console.log('被调起了')
console.log(r)
}
useEffect(() => {
wx.login({
success(res) {
console.log(res)
}
})
}, [])
return (
<div className='main-wrap'>
<wx-button
open-type='getUserInfo'
bindgetuserinfo={handleGetUserInfo}
>
获取用户信息
</wx-button>
</div>
)
}
看看complete有回调不
<wx-button
open-type='getUserInfo'
// getuserinfo={handleGetUserInfo}
complete={handleGetUserInfo}
>
获取用户信息
</wx-button>
加监听可以,我写在这里好让其他人参考
function Main() { const userInfoButton = useRef() const userPhoneNumberButton = useRef() const handleGetUserInfo = r => { console.log(r) } const handleGetPhoneNumber = r => { console.log(r) } useEffect(() => { wx.login({ success(res) { console.log(res) } }) userInfoButton.current.addEventListener( 'getuserinfo', handleGetUserInfo ) userPhoneNumberButton.current.addEventListener( 'getphonenumber', handleGetPhoneNumber ) }, []) return ( <div className='main-wrap'> <wx-button ref={userInfoButton} open-type='getUserInfo'> 获取用户信息 </wx-button> <wx-button ref={userPhoneNumberButton} open-type='getPhoneNumber'> 获取用户手机号码 </wx-button> </div> ) }