javascript - 当我从数据库中获取图像文件路径时,React Native 不显示图像
问题描述
我有一个带有课程表的数据库。
我想通过字段图像列中保存的图像路径显示图像。
在我的反应原生应用程序中,我有一个组件列出了购物车的图像保存在磁盘中的购物车
喜欢:C:\Users\Public\Pictures\Rectangle_2.png
。然后我将路径放在图像列中。
购物车列表.js
import Carts from './../Cart';
const Item = ({item}) => {
return (
<Carts
name={item.name}
price={item.price}
offPrice={item.offPrice}
image={item.image}
/>
);
};
class CartList extends React.Component {
constructor(props) {
super(props);
this.state = {
data: [],
};
}
componentDidMount() {
this.requestAPI();
}
requestAPI = () => {
const apiURL = 'http://myApi/api/courses';
fetch(apiURL)
.then(response => response.json())
.then(responseJson => {
this.setState({
data: responseJson,
});
});
};
renderItem = ({item}) => {
return <Item item={item} />;
};
render() {
return (
<>
<FlatList
data={this.state.data}
renderItem={this.renderItem}
keyEtractor={item => item.id.toString()}
/>
</>
);
}
}
我通过购物车中的道具访问图像路径。
购物车.js
const Cart = (props) => {
return (
<View
<Image
style={{
width: '40%',
height: 100,
}}
source={{uri:props.image}}
/>
</View>
);
};
export default Cart;
当我运行该应用程序时,我收到此错误:
我怎么解决这个问题?
解决方案
如果您的图像路径不正确,则会发生这种情况,请检查您的图像远程路径是否正确,我认为图像路径具有误导性。
推荐阅读
- embedded-jetty - Embedded Jetty 9 - 我需要 Websocket 服务器、REST Servlet 和文件服务器
- java - androidx.constraintlayout.widget.ConstraintLayout$LayoutParams 不能转换为 android.widget.RelativeLayout$LayoutParams
- arrays - 避免多次计算的更有效方法?
- exception - 为什么要在 Webflux 应用程序中构建自己的错误/异常处理?
- javascript - Cypress: How to get Href attribute value, redirect and match the URL with value
- alexa-skills-kit - 如何将值列表传递给意图中的alexa插槽
- tensorflow - 导出没有变量的 TensorFlow 模型
- javascript - 什么是 javascript monorepo 的正确方法
- java - 在java 8中与生菜建立redis连接的正确方法
- java - 我正在尝试创建一个二叉搜索树并打印这棵树的预购