繁体   English   中英

如何将 create-react-app 上的图像添加到 static 文件夹

[英]How to add an images on create-react-app to static folder

我有一个使用 create-react-app 的 React 应用程序,我目前正在学习 PWA。 我想在离线时加载图像,并且我已经阅读了一些告诉我在 serviceWorker 上进行设置的文章。 我应该弹出 create-react-app 还是有其他方法?

第 1 步:在您的 React 应用程序中创建一个文件夹并将图像粘贴到该文件夹中(例如:images/img.png)

第 2 步:打开您的 App.js 或您要导入该图像的任何文件

第 3 步:从 'images/img.png' 导入 sampleImage

第 4 步:在 render() 方法中使用 sampleImage Object

 <Image
            source={sampleImage}
            style={{
              flex: 1,
              justifyContent: "center",
              width: Dimensions.get("window").width,
              height: Dimensions.get("window").height / 2,
              resizeMode:"center"
            }}
          />

如果您需要创建 static 文件夹,您必须将您的文件夹放到“公共”文件夹

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM