我的文件夹结构:
资产
——图像
——potrait.png
src
——file.js
我想在file。js中加载我的图像,但是会抛出错误
<Image source={require('../assets/images/potrait.png')} />
错误:
错误:错误:无法解析模块../assets/images/potrait.png从D:munishDesktopInvictus touch -appsrc reactativeccamera .js:
这些文件都不存在:
- potrait.png
- 资产 potrait.png图像指数(.native | .android.js | .native.js | . js | .android.json | .native.json | . json | .android.ts | .native.ts | .ts | .android.tsx | .native.tsx | .tsx)
遗憾的是,react禁止src之外的导入。您应该将它们移动到src或public
文件夹中,在那里它可以通过/
访问(不推荐,因为它会复制图像,应该避免为最佳优化)。
您尝试过这种语法吗?
<Image source={{uri: localPath}}/>