Vuejs 嵌套 v-for 和 <tr> 标签问题

Joh*_*ohn 1 html binding html-table vue.js v-for

当我尝试在 a 中嵌套 a 并在每个 a 上绑定 v-for 时,vue 抱怨属性未定义。有什么问题?

<table>
  <thead></thead>
  <tbody>
    <tr v-for="item in items">
      <td>{{ item.name }}</td>
      <tr v-for="child in item.children">
        <td>{{ child.name }}</td>
      </tr>
    </tr>
  </tbody>
</table>
Run Code Online (Sandbox Code Playgroud)

这是一个js小提琴: https: //jsfiddle.net/78s3qnz5/

art*_*oju 5

如果您想使用行,您还可以使用模板标签。

<table>
  <thead></thead>
  <tbody>
    <template v-for="item in items">
      <tr>
        <td>{{ item.name }}</td>
      </tr>
      <tr v-for="child in item.children">
        <td>{{ child.name }}</td>
      </tr>
    </template>
  </tbody>
</table>
Run Code Online (Sandbox Code Playgroud)