[英]How to add an images on create-react-app to static folder
I have a React apps using create-react-app and I'm currently learning about PWA.我有一个使用 create-react-app 的 React 应用程序,我目前正在学习 PWA。 I want to load an images when offline and I've read some of article that told me to setup on serviceWorker.我想在离线时加载图像,并且我已经阅读了一些告诉我在 serviceWorker 上进行设置的文章。 Should I eject the create-react-app or is there any other way?我应该弹出 create-react-app 还是有其他方法?
Step 1: Create a Folder in your React Application And paste the image into that folder (eg: images/img.png)第 1 步:在您的 React 应用程序中创建一个文件夹并将图像粘贴到该文件夹中(例如:images/img.png)
Step 2: Open your App.js or any File where you want to import that Image第 2 步:打开您的 App.js 或您要导入该图像的任何文件
Step 3: import sampleImage from 'images/img.png'第 3 步:从 'images/img.png' 导入 sampleImage
Step 4: use the sampleImage Object inside your render() method第 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"
}}
/>
if you need to create a static folder, you must put your folder to the 'public' folder如果您需要创建 static 文件夹,您必须将您的文件夹放到“公共”文件夹
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.