简体   繁体   English

使用Vue JS访问多维数组

[英]Access multidimensional array with Vue JS

How can I access properties in objects inside multidimensional arrays using v-for with VueJS? 如何在VueJS中使用v-for访问多维数组内部对象的属性?

var arr =[{"fruit": {"fruitName": "apple"}, "vegetable":[{"vegetableName": "carrot" }]}];

Trying to print it like: 尝试将其打印为:

  <ul v-for="x in arr">
    <li>{{ x.fruit.fruitName }}</li>
    <li>{{ x.vegetable.vegetableName }}</li>
  </ul>

Can only print the fruitname, can't access the property in the array inside the array. 只能打印水果名称,不能访问数组内部的数组中的属性。

Use 0 index to get value since it's property of nested object inside an array. 使用0索引获取值,因为它是数组内嵌套对象的属性。

<li>{{ x.vegetable[0].vegetableName }}</li>
<!--            --^^^--                 -->

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM