javascript 参考错误:找不到变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47231429/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ReferenceError: Can't Find Variable
提问by Eli M
So i'm new to React Native but every time i put a new Component like a Button or an Image from Facebooks React Native Doc's i keep getting a "ReferenceError : Can't Find Variable" error on the simulator? This honestly happens when i add any other piece of code other than Text. Am i not linking something incorrectly? Anything would help.
所以我是 React Native 的新手,但是每次我从 Facebook 的 React Native Doc's 放置一个新的组件(如按钮或图像)时,我都会在模拟器上收到“ReferenceError : Can't Find Variable”错误?老实说,当我添加文本以外的任何其他代码时,就会发生这种情况。我没有错误地链接某些东西吗?任何事情都会有所帮助。
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {
Platform,
StyleSheet,
Text,
View
} 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',
});
export default class App extends Component<{}> {
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
This is a new App!
</Text>
<Text style={styles.instructions}>
To get started, edit App.js
</Text>
<Text style={styles.instructions}>
{instructions}
</Text>
<Button
onPress={onPressLearnMore}
title="Learn More"
color="#841584"
accessibilityLabel="Learn more about this purple button"
/>
<Text style={{color: 'blue'}}>Hello</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'white',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
**ERROR This is the error
**错误 这是错误
回答by Mirakolous
Try adding Buttonto the import like so:
尝试Button像这样添加到导入中:
import {
Platform,
StyleSheet,
Text,
View,
Button
} from 'react-native';

