Javascript React本机项目中出现意外标记
我试图以此作为从书中ES5到ES6的重构指南;然而,我似乎无法找到我意想不到的代币问题。这些文件都给了我一个问题,就在构造函数完成之后。感谢您的帮助 WeatherProject.jsJavascript React本机项目中出现意外标记,javascript,react-native,Javascript,React Native,我试图以此作为从书中ES5到ES6的重构指南;然而,我似乎无法找到我意想不到的代币问题。这些文件都给了我一个问题,就在构造函数完成之后。感谢您的帮助 WeatherProject.js class WeatherProject extends Component { constructor(props) { super(props); this.state = { zip: '', forecast: null}; }, _handleTextChange(event){ let zi
class WeatherProject extends Component {
constructor(props) {
super(props);
this.state = { zip: '',
forecast: null};
},
_handleTextChange(event){
let zip = event.nativeEvent.text;
this.setState({zip: zip});
fetch('http://api.openweathermap.org/data/2.5/weather?q='
+ zip + '&units=imperial')
.then((response) => response.json())
.then((responseJSON) => {
console.log(responseJSON);
this.setState({
forecast: {
main: responseJSON.weather[0].main,
description: responseJSON.weather[0].description,
temp: responseJSON.main.temp
}
})
})
.catch((error) => {
console.warn(error);
})
},
render() {
let content = null;
if (this.state.forecast !== null) {
content = <Forecast
main={this.state.forecast.main}
description={this.state.forecast.description}
temp={this.state.forecast.temp}/>;
}
return (
<View style={styles.container}>
<Image source={require('image!flowers')}
resizeMode= 'cover'
style={styles.backdrop}>
<View style={styles.overlay}>
<View style={styles.row}>
<Text style={styles.mainText}>
Current weather for
</Text>
<View style={styles.zipContainer}>
<TextInput
style={[styles.zipCode,styles.mainText]}
returnKeyType='go'
onSubmitEditing={this._handleTextChange} />
</View>
</View>
{content}
</View>
</Image>
</View>
);
}
}
class WeatherProject扩展组件{
建造师(道具){
超级(道具);
this.state={zip:'',
预测:空};
},
_handleTextChange(事件){
让zip=event.nativeEvent.text;
this.setState({zip:zip});
取('http://api.openweathermap.org/data/2.5/weather?q='
+zip+'&单位=英制')
.then((response)=>response.json())
.然后((responseJSON)=>{
console.log(responseJSON);
这是我的国家({
预测:{
main:responseJSON.weather[0]。main,
description:responseJSON.weather[0]。description,
温度:responseJSON.main.temp
}
})
})
.catch((错误)=>{
控制台。警告(错误);
})
},
render(){
让content=null;
if(this.state.forecast!==null){
内容=;
}
返回(
香港现时天气
{content}
);
}
}
Forecast.js
class Forecast extends Component {
constructor(props) {
super(props);
this.state = {
zip: '',
forecast: {
main: 'Clouds',
description: 'few clouds',
temp: 45.7
}
};
},
render() {
return (
<View>
<Text style={styles.bigText}>
{this.props.main}
</Text>
<Text style={styles.mainText}>
Current conditions: {this.props.description}
</Text>
<Text style={styles.mainText}>
{this.props.temp} F
</Text>
</View>
);
}
}
类预测扩展组件{
建造师(道具){
超级(道具);
此.state={
zip:“”,
预测:{
主要内容:"云",,
描述:'少云',
温度:45.7
}
};
},
render(){
返回(
{this.props.main}
当前条件:{this.props.description}
{this.props.temp}F
);
}
}
删除每个函数末尾的逗号。在ES6语法中,函数后不再需要逗号您可以发布收到的错误吗。