React本机项目中的意外令牌
Unexpected Token in a React Native Project
我在调用ES6方法时尝试使用此绑定上下文。如何从被称为回调的方法中访问对象?作为从本书的ES5到ES6的重构指南;然而,我似乎无法找到我意想不到的代币问题。在构造函数函数完成后,这两个文件都给了我一个问题。感谢您的帮助。
WeatherProject.js
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>
);
}
}
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>
);
}
}
删除每个函数末尾的逗号。在ES6语法中,函数之后不再需要逗号
相关文章:
- React JS:未捕获(在承诺中)语法错误:在位置 0 的 JSON 中意外<令牌
- jQuery$.getJSON抛出意外令牌
- 为什么我在下面的..of循环中得到意外令牌
- 组件中的ReactJS意外令牌
- AngularJS $http GET 请求到本地 JSON 文件返回语法错误:意外令牌]
- 巴别塔,意外令牌 (15:33) ::.
- Sencha 2.0 和 Codeigniter RESTful API 生成未捕获的语法错误:意外令牌:
- 在事件上使用 jquery 时出现意外令牌
- JSON 中位置 4 处的意外令牌<
- 意外令牌 ) 在我的代码中
- Electron 和 Babel 6 异步/等待抛出意外令牌
- “JSON.parse(str)”返回“意外令牌c”,但str是一个字符串
- jQuery after() uncatch SyntaxError: 意外令牌 ILLEGAL
- 使用节点javascript的意外令牌ILLEGAL
- Javascript/JQuery-Chrome意外令牌
- Ajax 帖子未捕获语法错误:意外令牌非法
- angularjs-SyntaxError:请求从服务器返回时出现意外令牌
- jquery:使用ember的意外令牌C
- React本机项目中的意外令牌
- 解析有效的 JSON 得到“语法错误:意外令牌非法”