我编写了一个简单的iOS程序来使用React Native显示图像. 'use strict';var React = require('react-native');var { Image} = React;var styles = React.StyleSheet.create({ base: { height: 400, width: 400 }});class SimpleApp extends
'use strict'; var React = require('react-native'); var { Image } = React; var styles = React.StyleSheet.create({ base: { height: 400, width: 400 } }); class SimpleApp extends React.Component { render() { return ( <Image style={styles.base} source={require('image!k')} //source={{uri: 'http://news.xinhuanet.com/world/2015-05/09/127782089_14311512601821n.jpg'}} /> ) } } React.AppRegistry.registerComponent('SimpleApp', () => SimpleApp);
但是我从iPad屏幕上收到了消息:
"Failed to print error:","'undefined' is not an object (evaluating 'stackString.split')"
当我更改代码以使用图像网址时
//source={require('image!k')} source={{uri: 'http://news.xinhuanet.com/world/2015-05/09/127782089_14311512601821n.jpg'}}
我只得到一个红色的矩形边框.
当我使用另一个js文件时,一切运行良好.“Hello World”可以在iPad屏幕上显示.
'use strict'; var React = require('react-native'); var { Text, } = React; class SimpleApp extends React.Component { render() { return ( <Text>Hello World</Text> ) } } React.AppRegistry.registerComponent('SimpleApp', () => SimpleApp);确保您使用的是最新版本的React Native.使用React Native 0.4.4以下工作:
本地形象
<Image style={styles.base} source={require('image!tabnav_settings')} />
还要确保将要使用的图像添加到图像资源:
远程图像
<Image style={styles.base} source={{uri: 'http://i.stack.imgur.com/DfkfD.png'}} />