我刚安装了反应本机默认项目并在默认类中添加了一个函数,但它没有被执行
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>
);
}
}
1 回答
React-Native中Alert的正确方法是:
谢谢..!
~ Praz