今天要來看Alpine.js和Vue.js的迴圈,
兩者也是非常非常像,
在Alpine.js中使用x-for,
在Vue.js中使用v-for,
我們直接看範例吧。
(可參考Day7)
html
<ul>
  <template x-for="post in posts" :key="post.id">
    <li x-text="post.title"></li>
  </template>
</ul>
須注意!在使用x-for時,務必要搭配template標籤做使用
html
<ul>
  <li v-for="post in posts" :key="post.id">
    {{ post.title }}
  </li>
</ul>
比較兩者迴圈差異
x-for屬性x-text列印出來;Vue.js用雙花框{{ }}包夾要列印的元素