为什么onPress的按钮中的警报会使expo应用程序崩溃?
问题描述:
此代码有效。为什么onPress的按钮中的警报会使expo应用程序崩溃?
<Button
onPress = {() => testfn(this.state.text)}
title = 'Send'
color = '#1DA237'
/>
function testfn(theString) {
alert(theString);
}
但这个代码崩溃上构建世博会应用。
<Button onPress = {() => alert(this.state.text)} title = 'Send' color = '#1DA237' />
任何人都可以澄清对我来说这是为什么?
谢谢!
编辑:
我上LG G3与世博会的客户端版本1.18.4
答
进口警报运行的是Android 6.0的react-native
import {
Alert,
} from 'react-native';
然后调用它象下面这样:
function testfn(theString){
Alert.alert(theString);
}
或
<Button
onPress = {() => Alert.alert(this.state.text)}
title = 'Send'
color = '#1DA237'
/>
+0
工作!谢谢!我仍然不知道为什么它没有给我一个错误,而是只是坠毁。通常它会给我类似'无法找到变量:警报'。 –
+1
'alert'是Javascript函数,因此它将在开发时供您使用,但在捆绑时它将无法访问。 –
BTW什么是 '警戒' 在这里?你是使用功能还是类组件。更多的代码可以帮助 –
什么是错误信息? –
@RaviRaj https://www.w3schools.com/jsref/met_win_alert.asp –