React native 无法在React本机默认项目中将类作为函数调用
我刚刚安装了react本机默认项目,并在默认类中添加了一个函数,但它并没有得到执行React native 无法在React本机默认项目中将类作为函数调用,react-native,React Native,我刚刚安装了react本机默认项目,并在默认类中添加了一个函数,但它并没有得到执行 import React, {Component} from 'react'; import {Platform, StyleSheet, Text, View, Alert,TouchableOpacity} from 'react-native'; const instructions = Platform.select({ ios: 'Press Cmd+R to reloa
import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View, Alert,TouchableOpacity} from 'react-native';
const instructions = Platform.select({
ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu',
android:
'Double tap R on your keyboard to reload,\n' +
'Shake or press menu button for dev menu',
});
type Props = {};
export default class App extends Component {
//the function i added
clickMe() {
Alert("started");
}
render() {
return (
<View>
<Text >Welcome to Native!</Text>
<Text >To get started, edit App.js</Text>
<TouchableOpacity onPress={() => this.clickMe()}>
<Text>{instructions}</Text>
</TouchableOpacity>
</View>
);
}
}
React Native中警报的正确方式是:
Alert.alert(
'Alert Title',
'My Alert Msg',
[
{text: 'Cancel', onPress: () => console.log('Cancel Pressed'), style: 'cancel'},
{text: 'OK', onPress: () => console.log('OK Pressed')},
],
{ cancelable: false }
)
谢谢你
~z~普拉斯