react-native - 我的项目中未显示的图像反应原生
问题描述
我正在启动 React Native 并使用 Visual Studio Code。
图像组件不起作用,我确实喜欢这个,但没有显示背景图像。
import React, { Component } from 'react';
import { View, StyleSheet, TouchableOpacity, Text, Dimensions, Image} from 'react-native';
import Icon from 'react-native-vector-icons/Ionicons';
import GLOBAL from '../../global';
import I18n from '../../i18n'
var { width, height } = Dimensions.get('window');
export default class EsseGroupScreen extends Component {
render() {
return(
<View style = {styles.container}>
{this.renderHeader()}
<Image source={require('../../assets/esse_group_back.png')} style={styles.imgBack} />
</View>
)
}
renderHeader() {
return(
<View style={styles.header}>
</View>
)
}
}
const styles = StyleSheet.create({
container: {
flexDirection: 'column',
backgroundColor: 'white'
},
imgBack: {
flex: 1,
alignSelf: 'stretch',
width: width,
height: height-50,
resizeMode: 'contain'
}
});
我尝试了很多案例,但找不到明确的答案。
<Image source={require('../../assets/esse_group_back.png')} style={styles.imgBack} />
上面的代码不起作用,请帮助我。
我的依赖项如下。
"dependencies": {
"react": "^16.8.6",
"react-native": "^0.60.0",
"react-native-grid-view": "https://github.com/lucholaf/react-native-grid-view.git",
"react-native-i18n": "^2.0.15",
"react-native-numeric-input": "^1.8.0",
"react-native-scalable-image": "https://github.com/ihor/react-native-scalable-image.git",
"react-native-tabbar-bottom": "^1.0.4",
"react-native-vector-icons": "^6.6.0",
"react-navigation": "https://github.com/Maxeh/react-navigation.git",
"rn-viewpager": "https://github.com/zbtang/React-Native-ViewPager.git"
},
"devDependencies": {
"@babel/core": "^7.5.0",
"@babel/runtime": "^7.5.2",
"@react-native-community/eslint-config": "^0.0.5",
"babel-jest": "^24.8.0",
"eslint": "^6.0.1",
"jest": "^24.8.0",
"metro-react-native-babel-preset": "^0.55.0",
"react-test-renderer": "^16.8.6"
},
解决方案
问题在于您的图像路径。您提供的图像源路径不正确。我用我的图像文件夹尝试了你的代码,它工作正常。只需检查图像路径并替换为正确的路径。
推荐阅读
- c# - .NET 5 API 和 React UI 身份验证使用 Azure AD B2C - Bearer error="invalid_token", error_description="签名无效"
- ruby-on-rails - 在使用正则表达式查询之前从 Postgres DB 中的字段中删除标点符号
- nginx - WSL2 - Magento 2.4-Nginx - Css 和 Js 问题
- pygame - 有没有正确的方法在pygame中实现游戏结束并重新启动屏幕?
- grok - Grok 模式可能会关闭 - 任何建议将不胜感激
- installation - 如何更新geoip遗留
- wordpress - WordPress 自定义分类法 - 哎呀!找不到该页面 - 错误 404
- python - 在 PowerPoint 中创建“PicturePlaceholder”并使用 Python-pptx 访问它
- java - Java 通过添加特定的小时数来计算时间,但只考虑工作时间和非周末日
- java - 错误:在 Android Studio 中找不到符号类