我从React Native官方教程中引用了ScrollView
。
图像代码就像<Image source={require('./img/favicon.png')} />
当我试着建造它时,它显示出
开发服务器返回响应错误代码:500 URL:http://10.0.2.2:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false正文:
{"from":"F:\\ReactNativeProject\\FirstProject\\index.android.js","to":"./img/favicon.png","message":"Unable to resolve module `./img/favicon.png` from `F:\\ReactNativeProject\\FirstProject\\index.android.js`: Directory F:\\ReactNativeProject\\FirstProject\\img\\favicon.png doesn't exist","name":"UnableToResolveError","type":"UnableToResolveError","errors":[{}]}
我将图像设置为我的文件夹F:\ReactNativeProject\FirstProject\img
图像名称为favicon
为什么显示错误?有人能告诉我为什么吗?谢谢。
新错误为F:/ReactNativeProject/FirstProject/index.android.js: Unexpected token (9:25) at F:\ReactNativeProject\FirstProject\index.android.js:9:25
我的密码是
import React, { Component } from 'react';
import{ AppRegistry, ScrollView, Image, Text, View } from 'react-native'
class IScrolledDownAndWhatHappenedNextShockedMe extends Component {
render() {
return(
<ScrollView>
<Image source={../../img/favicon.png} />
</ScrollView>
);
}
}
AppRegistry.registerComponent('FirstProject', () => IScrolledDownAndWhatHappenedNextShockedMe);
2条答案
按热度按时间prdp8dxp1#
require
是用来引用一个模块/文件。因此你得到的错误。应为:
ycl3bljg2#
您可以使用此解决方案解决此问题