【发布时间】:2021-06-01 13:18:17
【问题描述】:
我正在使用 Vue 组件来呈现一些表头,如下所示:
render (createElement) {
return createElement('div', { class: 'header' },
Array.apply(null, { length: this.initHours.length }).map(() => {
return createElement('div', { class: 'frame' }, this.getHourIndex() )
})
)
}
问题是当 console.log 在 hourIndex 上完成时(通过数组运行)进入无限循环。
getHourIndex 函数是:
getHourIndex () {
const headerData = this.initHours[this.hourIndex]
this.hourIndex++
console.log(this.hourIndex) /// this is what's telling me it's an infinite loop
return headerData
}
任何关于为什么这样做这个无限循环的方向(考虑到 hourIndex 数组只有 25 个元素)将不胜感激。
【问题讨论】:
标签: javascript vue.js vue-component vue-reactivity vue-render-function