【发布时间】:2021-08-16 23:32:02
【问题描述】:
我有一个按钮,当你点击它时,它会调用一个函数,从 react.js 网站返回一个 Image 对象,但是当我点击按钮时图像没有显示。
这是我的代码:
import { StatusBar } from 'expo-status-bar';
import React from 'react';
import { StyleSheet, Text, View, Button, Image } from 'react-native';
export default function App() {
function getImage() {
return (
<Image
source={{
uri: 'https://reactjs.org/logo-og.png',
method: 'POST',
headers: {
Pragma: 'no-cache',
},
body: 'Your Body goes here',
}}
style={{width: 400, height: 400}}
/>
)
}
return (
<View style={styles.container}>
<Button
onPress={getImage}
title="Click me"
color="#841584"
/>
<StatusBar style="auto" />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
【问题讨论】: