【发布时间】:2015-11-30 17:21:54
【问题描述】:
我是 react native 的新手,想在 Android 和 iOS 中构建一个小型测试应用。
我在 index.ios.js 和 index.android.js 文件旁边创建了一个 images 目录。
我下面的代码产生了一个红屏错误,说“无法解析模块./images/tree.png...无效目录...”:
'use strict';
var React = require('react-native');
var {
AppRegistry,
StyleSheet,
Text,
View,
Image,
} = React;
var TestApp = React.createClass({
render: function() {
return (
<View>
<Text>test app</Text>
<Image
style={styles.thumbnail}
source={require('./images/tree.png')} /> />
</View>
);
},
});
var styles = StyleSheet.create({
thumbnail: {
width: 100,
height: 100,
},
});
AppRegistry.registerComponent('TestApp', () => TestApp);
我应该把我的图片放在哪里,我应该如何引用它们?
【问题讨论】:
-
根据React Native docs
The image name is resolved the same way JS modules are resolved. In the example above the packager will look for my-icon.png in the same folder as the component that requires it.在不知道您的文件夹结构的情况下,听起来您的文件夹与您的js文件位于同一位置。您是否阅读过从以前的 RN 版本升级?有一些构建系统钩子可能会有所帮助。 -
升级我的 RN 版本成功了。感谢您的回复。
标签: react-native