鍍金池/ 問答/HTML/ iview的跑馬燈在iview中一直報(bào)警告錯(cuò)誤啥情況

iview的跑馬燈在iview中一直報(bào)警告錯(cuò)誤啥情況

跑馬燈組件也就是輪播圖每次加載圖片報(bào)警告錯(cuò)誤

跑馬燈組件代碼

<Row class="header-Row">
            <!-- 輪播圖 -->
            <Col :lg='{span:10,offset:3}' :xs='{span:24,offset:0}'>
            <Carousel v-model="value1" loop autoplay >
                <CarouselItem> 
                    <div class="demo-carousel">
                        <div class="lunbo">
                            <img :src="lunbo[0].url" alt="">
                            <div class="lunbo-div">
                               <Strong>{{lunbo[0].title}}</Strong>
                                <p>{{lunbo[0].content}}</p>
                            </div>
                        </div>
                    </div>
                </CarouselItem>
                <CarouselItem>
                    <div class="demo-carousel">
                        <div class="lunbo">
                            <img :src="lunbo[1].url" alt="">
                            <div class="lunbo-div">
                                <Strong>{{lunbo[1].title}}</Strong>
                                <p>{{lunbo[1].content}}</p>
                            </div>
                        </div>
                    </div>
                </CarouselItem>
                <CarouselItem>
                    <div class="demo-carousel">
                        <div class="lunbo">
                            <img :src="lunbo[2].url" alt="">
                            <div class="lunbo-div">
                               <Strong>{{lunbo[2].title}}</Strong>
                                <p>{{lunbo[2].content}}</p>
                            </div>
                        </div>
                    </div>
                </CarouselItem>
            </Carousel>
            </Col>

鉤子獲取圖片代碼

 created () {
        var _this=this;
        //初始化文章列表
        this.start();
        //獲取輪播列表
        axios.post('./index/mainpage/getlunbo',qs.stringify({id:1}))
        .then(res=>{
            _this.lunbo=res.data;
        })}

報(bào)的錯(cuò)誤

clipboard.png

剛開始不能讀那些屬性
感覺鉤子怎么比他的dom渲染慢半拍

回答
編輯回答
心上人

因?yàn)槟阍赾reated時(shí)候去拿的數(shù)據(jù)啊,而且請(qǐng)求數(shù)據(jù)是異步的,你拿到數(shù)據(jù)之前頁(yè)面已經(jīng)渲染完了,這個(gè)時(shí)候lunbo這個(gè)數(shù)組還是空的,所以lunbo[2]肯定沒有數(shù)據(jù)了,給Carousel加個(gè)v-if="lunbo.length"

2017年1月20日 01:08