【发布时间】:2018-11-29 14:09:50
【问题描述】:
我正在制作一个包含随机创建的数字的表格,但是当我在 v-for 中调用 contacts() 时,出于某种原因, 我收到了这个红色警告:
vue.esm.js?efeb:591 [Vue 警告]:您可能在组件渲染函数中有无限更新循环。在 src\App.vue 的---> 中找到
有一堆空数组,比如“[]...”
为什么会这样以及如何解决?
<template>
<div id="app">
<table border=1 width =50% id="list">
<tr v-for="i in [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]">
<td v-for="contact in contacts()">{{contact}}</td>
</tr>
</table>
</div>
</template>
<script>
import Vue from 'vue'
export default {
name: "App",
data: function() {
return {
result: [],
row: Math.floor(Math.random() * 16) + 1
}
},
created() {
let start = Math.floor(Math.random() * 16) + 1
for (var i = 0; i < 16; i++) {
this.result[i] = start++
if (start > 16) start = 1
}
},
methods: {
contacts: function() {
let snapshot = this.result.splice(0, this.row)
console.log(snapshot)
return snapshot
}
}
}
</script>
【问题讨论】:
标签: vue.js