vue中用于循环的指令是

2024-04-30

vue 中用于循环遍历数据数组或对象的指令是 v-for,语法为 。参数包括:遍历项 item、可选索引 index 和要遍历的数据 items。

Vue 中用于循环的指令

Vue 中使用 v-for 指令进行循环遍历数据数组或对象。

语法:

<code class="html"><template v-for="(item, index) in items"></template></code>

参数:

  • item:当前循环项
  • index:当前循环项的索引(可选)
  • items:要遍历的数据数组或对象

用法:

  1. 遍历数组:
<code class="html"><ul>
<li v-for="item in items">{{ item }}</li>
</ul></code>
  1. 遍历对象:
<code class="html"><ul>
<li v-for="(value, key) in object">{{ key }}: {{ value }}</li>
</ul></code>
  1. 循环索引:
<code class="html"><ul>
<li v-for="(item, index) in items">{{ index + 1 }}. {{ item }}</li>
</ul></code>

以上就是vue中用于循环的指令是的详细内容,更多请关注北冥有鱼其它相关技术文章!