[英]Can't find variable: Button - React Native
我正在嘗試使用 React Native 中的按鈕創建一個簡單的應用程序,但到目前為止,每次運行我的代碼時,它都會給我一個錯誤,提示“找不到變量:按鈕”。 我希望我的標題位於頂部(已完成),屏幕中央有一個按鈕,觸摸時會發出警報。
我已經瀏覽了幾個在線教程,但找不到解決方案。
這是我的代碼:
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View
} from 'react-native';
class Project extends Component {
render() {
return (
<View style={styles.container}>
<Text style={styles.Title}>
Lucas's App
</Text>
<View style={styles.buttonContainer}>
<Button
onPress={() => { Alert.alert('You tapped the button!')}}
title="Press Me"
/>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#F5FCFF',
},
Title: {
color: '#000000',
marginTop: 13,
paddingLeft:100,
paddingRight:100,
fontFamily: 'Avenir',
fontSize: 30,
},
buttonContainer: {
margin: 20
},
});
AppRegistry.registerComponent('Project', () => Project);
提前致謝。
您需要確保導入按鈕。 您可以通過在代碼之前添加以下內容來做到這一點:
import {
AppRegistry,
StyleSheet,
Text,
View,
Button,
Alert
} from 'react-native';
[或者只是在導入列表中添加按鈕]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.