Looping through data array properties in VueJS

断了今生、忘了曾经 提交于 2019-12-11 05:57:07

问题


In vuejs you can do list rendering in the template like

<td v-for="item in items"></td>......

But can you iterate over that same data array property like....

for(var i = 0; i < this.items.length; i++)
 this.$data.items[i]

回答1:


yes

Just don't worry about the this.$data.items, instead this.items, although it would also work ...




回答2:


this post is quite old, but this can be useful to anyone who wants to iterate into an array of object.

Instead of:

for(var i =0; i < this.items.length; i++) {
  console.log(this.items[i]);
}

You can do this a little bit more concisely and more readable (in my opinion):

this.items.forEach((item) => {
  console.log(item);
})


来源:https://stackoverflow.com/questions/40864494/looping-through-data-array-properties-in-vuejs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!