如何将 Alert 替换为 navigation.navigate('Home")? like Open the new screen in catch
Posted
技术标签:
【中文标题】如何将 Alert 替换为 navigation.navigate(\'Home")? like Open the new screen in catch【英文标题】:how to replace Alert into navigation.navigate('Home")? like Open the new screen in catch如何将 Alert 替换为 navigation.navigate('Home")? like Open the new screen in catch 【发布时间】:2019-11-26 07:14:12 【问题描述】:如何打开新画面?
赞:navigation.navigate('Home")
async function handleLoginWithPhonePressed()
try
------------------------
catch (err)
//Alert.alert(`Failed to login with phone $err.message`)
() => navigation.navigate('Home")
【问题讨论】:
请不要附上截图,在你的问题中添加代码 请不要上传images of code。无法复制它们以重现该问题,未来的读者无法搜索它们,并且 imgur 在某些工作场所和国家/地区被屏蔽。请以文本形式发布实际代码以创建minimal reproducible example。 async function handleLoginWithPhonePressed() try const token = await AccountKit.loginWithPhone() if (!token) Alert.alert('用户取消了手机登录!') return setAuthToken( token) getCurrentUser() catch (err) Alert.alert(Failed to login with phone $err.message
)
好的,我会试试的。
【参考方案1】:
我不太明白你的问题,因为你已经回答了自己。
将 Alert.alert 替换为路由器的代码。
try
.....
catch
//open the new screen or next page
//navigation.navigate("xyz")
【讨论】:
【参考方案2】:async function handleLoginWithPhonePressed()
try
const token = await AccountKit.loginWithPhone()
if (!token)
Alert.alert('User cancelled the login with phone action!')
return
setAuthToken(token)
getCurrentUser()
catch (err)
Alert.alert(Failed to login with phone $err.message)
【讨论】:
【参考方案3】:这是正确的答案。
this.props.navigation.navigate('Home")
async function handleLoginWithPhonePressed()
try
------------------------
catch (err)
//Alert.alert(`Failed to login with phone $err.message`)
//() => navigation.navigate('Home")
this.props.navigation.navigate('Home");
【讨论】:
以上是关于如何将 Alert 替换为 navigation.navigate('Home")? like Open the new screen in catch的主要内容,如果未能解决你的问题,请参考以下文章