如何正确使用 v-if 和 v-for 嵌套对象 vue js

How to properly v-if and v-for nested object vue js

我无法使用 v-for 渲染嵌套对象内容,有一个包含对象的 prop,但是当我执行 v-if="prop" 时 div 没有显示。请帮助如何解决它。这是我用于渲染的语法:

<div v-if="statisticBrandBrowsers && statisticBrandBrowsers.length">
  <div v-for="(item, index) in statisticBrandBrowsers">
    <div>View: {{item.page_view.hits}}</div>
  </div>
</div>

我的道具:

问题出在条件渲染内部,而不是 v-for 循环内部,因为对象没有名为 length 的 属性,因此您应该执行以下操作:

<div v-if="statisticBrandBrowsers && Object.values(statisticBrandBrowsers).length">

Object.values(statisticBrandBrowsers) 会给你一个包含 length 属性

的数组