im尝试一个示例。这是我的代码
导出默认类NewApp扩展了组件{
render() {
var data = this.getWeatherFromApiAsync()
return (
if(data != null )
{
<View>
<Text>got data</Text>
</View>
}else
{
<View>
<Text>no data</Text>
</View>
}
);
}
getWeatherFromApiAsync() {
return fetch('http://api.openweathermap.org/data/2.5/forecast/daily?q=94043&mode=json&units=metric&cnt=14&APPID=18dcba27e5bca83fe4ec6b8fbeed7827')
.then((response) => response.json())
.then((responseJson) => {
this.setState({isLoading: false, jsonData: responseJson});
console.log(responseJson);
return responseJson;
})
.catch((error) => {
console.error(error);
});
}
}
这给出以下错误
E:/REACT_NATIVE_PROJECTS/newApp/index.android.js: Unexpected token (25:6)
at E:REACT_NATIVE_PROJECTSnewAppindex.android.js:25:6
processBundleResult
DevServerHelper.java:381
access$400
DevServerHelper.java:65
execute
DevServerHelper.java:333
emitChunk
MultipartStreamReader.java:69
readAllParts
MultipartStreamReader.java:116
onResponse
DevServerHelper.java:321
execute
RealCall.java:126
run
NamedRunnable.java:32
runWorker
ThreadPoolExecutor.java:1113
run
ThreadPoolExecutor.java:588
run
Thread.java:818
我做错了什么。它是比较部分吗?
这就是我们在反应本机中使用条件渲染的方式:
{1 2 == 3&amp;&amp;我只有当左手为true}
时出现更正您的语法。
https://atticuswhite.com/blog/render-if-cornitionally-render-render-reakct-components/