我在动态添加到组件列表时遇到问题。
我已经在 vue 文档的数据元素“事物”中定义了列表。对于“事物”中的每个对象,页面上都会加载一个组件
data() {
return {
things: []
}
}
我使用类似下面的代码来加载页面上的每个内容。
<div v-for="thing in things" :key="thing.objectId">
然后我加载更多元素并将它们添加到列表中
let temp = JSON.parse(JSON.stringify(results))
vm.things = vm.things.concat(temp)
当我在 dev 中运行它时,我得到以下信息
[Vue 警告]:您可能在组件渲染函数中有无限更新循环。
除了错误消息之外,代码在开发模式下工作,但在生产中运行时会导致浏览器崩溃。
我已经把它缩小到这段代码,循环中有一点打印出一个标题,它是数据所属的月份,所以它可能会说一月,然后列出一月下的所有数据,然后到下个月等等
showDate(data) {
this.currentDataMonth = helperfunctionsgetDate_format_month_year(data)
if (this.currentDataMonth != this.currentmonth) {
this.currentmonth = this.currentDataMonth
return "<h2>" + this.currentmonth + "</h2>"
} else {
return ""
}