代码之家  ›  专栏  ›  技术社区  ›  ofey

vue.js v-for迭代变量次数

  •  0
  • ofey  · 技术社区  · 7 年前

    我想在一个范围内迭代表中的行。但我看到的所有例子都说明了如何对常数进行计算,例如,

    <div>
      <span v-for="n in 10">{{ n }} </span>
    </di
    

    对于这样一个变量,我该怎么做呢,

    <table>
       <tr v-for="(el, index) in form.repeat" :key="index">
          <td>hello</td>
       </tr>
    </table>
    

    谢谢

    1 回复  |  直到 7 年前
        1
  •  2
  •   Cathal Cronin    7 年前

    enter image description here

    在数据部分:

    data: () => ({'num_pis': 0})
    

    在模板部分,引用编号。这只是一个片段,我使用的是Vuetify的v-data-table。

    <template slot="items" slot-scope="props">
      <td class="table-content-style">{{ props.item.metric_name }}</td>
      <td v-for="i in num_pis">
        {{ props.item[i] }}
      </td>
    </template>
    

    Codepen Example

    推荐文章