引用图片报错Error while updating propety "src" of a view managed by :RCTImageView



  • render 组件里面有一个变量{img}, 创建组件后从网络获取图片地址然后再创建图片组件,把图片赋值给render里面的变量{img}就报错Error while updating propety "src" of a view managed by :RCTImageView,请问这是什么原因?


  • administrators

    贴代码,字数补丁



  • @sunnylqm

    Inimglist=React.createClass({
        getInitialState:function(){
            return ({dom:null})
        },
        creachot:function(){
            //appindex_hot
            var listd=[];
            fetch('http://m.jinguangan.com/?mobile=1&appindex_hot=1')
                .then((response) => response.json())
                .then((responseText) => {
                    responseText.hot.shift();
                    var backjson=responseText.hot
                    for(let i=0;i<backjson.length;i++)
                    {
                        listd.push(this.creatli(backjson[i].title,backjson[i].img,backjson[i].posttime,backjson[i].user,i))
    
                    }
                    this.setState({
                        dom: listd
                    });
    
                })
                .catch((error) => {
                    console.warn(error);
                })
        },
        render:function() {
            this.creachot();
            return (
                <View>
                    {this.state.dom}
                </View>
            )
        },
        creatli:function(title,img,time,user,key){
            return (
                <View key={key}>
                    <Text>{title}</Text>
                    <Image source={{uri:{img}}} style={{height:200,width:500}}/>
                    <View>
                        <Text>{user}</Text>
                        <Text>{time}</Text>
                    </View>
                </View>
            )
        },
    });
    

    新手代码比较乱^_^


  • administrators

    去掉img的括号
    uri: img



  • @sunnylqm 能显示了太好了,谢谢大神


登录后回复