![](/img/trans.png)
[英]How can I use default image if Image url gives 404 error in react native?
[英]how can I use Image in react native?
我想使用图像 uri 并渲染我的图像,但它没有显示我不知道为什么
这是我的代码嗨我正在使用 react-native
我想使用图像 uri 并渲染我的图像,但它没有显示我不知道为什么
这是我的代码
import React from 'react';
import styled from 'styled-components/native';
import {FlatList,
Dimensions,
ScrollView,
NativeSyntheticEvent,
NativeScrollEvent,
} from 'react-native';
import {useSelector,useDispatch} from 'react-redux';
const Container = styled.View`
`;
const Hey = styled.Text`
`;
const ImageContainer = styled.View`
border-top-width: 1px;
border-bottom-width: 1px;
border-color: #D3D3D3;
width: ${Dimensions.get('window').width}px;
height: 400px;
/* background: lightgray; */
`;
const ImageStyle = styled.Image`
`;
const Food = ({navigation}) => {
const {cookUp} = useSelector((state) => state.post);
console.log("cookUp:",cookUp);
return (
<>
{cookUp.length ? (
<FlatList
data={cookUp}
keyExtractor={(item) => String(item.id)}
// keyExtractor={(item, index) => {
// return `${index}`;
// }}
renderItem={({item}) => (
console.log("item.Images:",item.Images),
<ImageContainer>
<ImageStyle
source={{uri:item.Images[0].src}}
/>
</ImageContainer>
)}
/>
) :
(<Hey>hiaaaaaa</Hey>)
}
</>
);
};
export default Food;
这是控制台日志
如何修复我的代码? 你能帮我么??
试试这个方法
import {Image} from 'react-native';
<Image
source={{uri:item.Images[0].src}}
width={200}
height={200}
/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.