url - React Native 中的 URI 与 URL
问题描述
在 react-native 中,可以这样做:
const somePath = 'https://...'
<Image source={somePath} />
或者
const somePath = 'https://...'
<Image source={{uri: somePath}} />
根据我对网址的了解,URI 是 URL 和 URN 的超集。
问题
source
将网址作为 URL提供相关的潜在问题是什么?将网址
source
作为 URI 提供相关的潜在问题是什么?哪种提供图像地址的方法
source
更准确、更安全且面向未来?
解决方案
您提供的第一个代码示例不起作用
const somePath = 'https://...'
<Image source={somePath} />
一般来说,您应该使用 source 道具来提供像这样的本地图像
const someLocalImage = require("./assets/someImageName.png");
<Image source={someLocalImage} />
以及像这样显示远程图像的uri
<Image source={{uri: "https://example.com/someRemoteImagePath.png" />
也可以使用uri显示base64图片数据
<Image
source={{uri: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADMAAAAzCAYAAAA6oTAqAAAAEXRFWHRTb2Z0d2FyZQBwbmdjcnVzaEB1SfMAAABQSURBVGje7dSxCQBACARB+2/ab8BEeQNhFi6WSYzYLYudDQYGBgYGBgYGBgYGBgYGBgZmcvDqYGBgmhivGQYGBgYGBgYGBgYGBgYGBgbmQw+P/eMrC5UTVAAAAABJRU5ErkJggg=='}}
/>
在文档中阅读有关它的更多信息
https://facebook.github.io/react-native/docs/image.html#source
推荐阅读
- java - 如何使用 Camera2 API 获得稳定的恒定帧速率?
- c - 我可以重用请求对象吗?
- r - 抓取问答可以正常工作,除非一篇帖子的答案超过一页
- python - 根据分数对 CSV 文件进行排序
- scheme - 每次迭代如何保存新文件
- firebase - 将数据从 Firestore 加载到 BigQuery 的适当方法是什么?
- javascript - 使用 HTML 表单在 jQuery 中重定向
- rust - 在闭包内通过引用保持值
- redirect - 在 Spring Cloud Gateway 中使用自定义路由过滤器禁用重定向
- azure - 在 Azure Blob 存储中托管 ClickOnce 并使用自定义域