首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ImageBackground组件的问题反应-本机

ImageBackground组件的问题反应-本机
EN

Stack Overflow用户
提问于 2019-09-28 01:55:00
回答 1查看 448关注 0票数 0

返回renderRow时,图像背景组件有问题。

代码语言:javascript
复制
    import back1 from '../../assets/back1.jpg';

    renderRowpost = ({ item }) => {
        return ( 
                MORECONTENT....     
                {item.imgfondo ?  //IF EXIST BACK IMAGEN
                    <View key={"viwid_" + item.postid} style={styles.warptextopost}>
                        <ImageBackground source={back1}>
                            <Text key={"text_id" + item.postid} style={styles.stylpublictext} >{item.posttexto}</Text>
                        </ImageBackground>
                    </View>
                    : //as there is no image I place the text without background
                    <View key={"viwid_" + item.postid} style={styles.warptextopost}>
                         <Text key={"text_id" + item.postid} style={styles.stylpublictext} >{item.posttexto}</Text>
                    </View>
                }       
   )
   }


          //Where I show all the content I get from RenderrenderRowpost

                <FlatList
                    data={this.state.datapost}
                    renderItem={this.renderRowpost}
                    keyExtractor={(item, index) => index.toString()}
                />

我得到了以下错误:不变冲突: Element type无效--需要一个字符串(用于内置组件)或一个类/函数(用于复合组件),但get : undefined。您可能忘记从定义在其中的文件中导出组件,或者您可能混淆了默认的导入和命名导入。,但是如果我删除ImageBackground组件或放置一个图像组件(没有文本),如果它显示正常的内容,它只会在放置ImageBackground组件时给出错误,有任何解决方案吗?我需要在视图中放一张背景图片及其相应的文字,非常感谢..

EN

回答 1

Stack Overflow用户

发布于 2019-09-28 05:19:33

按以下方式加载图像

代码语言:javascript
复制
<ImageBackground source={require('../../assets/back1.jpg')}>
...
</ImageBackground>

我想您不能像在导入中加载js模块那样导入图像。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58142781

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档