在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ 使用v-for出現(xiàn)"TypeError:Cannot read pro

使用v-for出現(xiàn)"TypeError:Cannot read property 'xxx' of undefined"

clipboard.png
“{{period.period_name}}”去掉后,“{{period.this_period_start}}”就報錯了。
period.period_name、period.this_period_start、period.this_period_end、period.same_period_start、period.same_period_end都獲取不到。

<div class="period-list-box" v-for="{index,period} in period_list">
            <div class="period-list-item">
                <div class="period-content">
                    <div class="period-name">{{period.period_name}}</div>
                    <div class="period-time">
                        本期:{{period.this_period_start}}~{{period.this_period_end}} 同期:{{period.same_period_start}}~{{period.same_period_end}}
                    </div>
                </div>
                <div class="delete-period">
                    <img src="#">
                </div>
            </div>
        </div>

period_list輸出每個字段都添加了的

data.forEach((item) => {
                                    this.period_list.push({
                                        period_id: item.period_id,
                                        period_name: item.period_name,
                                        this_period_start: item.this_period_start,
                                        this_period_end: item.this_period_end,
                                        same_period_start: item.same_period_start,
                                        same_period_end: item.same_period_end,
                                    })
                                })
回答
編輯回答
薔薇花

...

{index, period} -->(period, index)

寫反了,而且是圓括號,別的錯還有沒有就暫時不知道了

2017年9月2日 14:26
編輯回答
苦妄

樓上回答的是對的,另外,如果你的list是從后臺請求回來的數(shù)據(jù)的話,最好在外層包裹一個<div v-if="period_list"></div>,確保數(shù)據(jù)請求回來再渲染dom,這樣百分百不會報錯了

2017年7月19日 22:34