- Full-Stack Vue.js 2 and Laravel 5
- Anthony Gore
- 117字
- 2021-07-02 19:57:20
List rendering
Thev-fordirective requires a special type of expression in the form ofitem in items, whereitemsis the source array, anditemis an alias for the current array element being looped over.
Let's work on theamenitiesarray first. Each member of this array is an object with atitleandiconproperty, that is:
{ title: 'something', icon: 'something' }
We'll add thev-fordirective into the template and the expression we assign to it will beamenity in amenities. The alias part of the expression, that is amenity, will refer, throughout the loop sequence, to each object in the array, starting with the first.
index.html:
<p class="container"> <p class="heading">...</p> <hr> <p class="about">...</p> <p class="lists"> <p v-for="amenity in amenities">{{ amenity.title }}</p> </p> </p>
It will render as:
<p class="container"> <p class="heading">...</p> <hr> <p class="about">...</p> <p class="lists"> <p>Wireless Internet</p> <p>Pets Allowed</p> <p>TV</p> <p>Kitchen</p> <p>Breakfast</p> <p>Laptop friendly workspace</p> </p> </p>
推薦閱讀
- Vue.js設計與實現
- 認識編程:以Python語言講透編程的本質
- Python神經網絡項目實戰
- Banana Pi Cookbook
- Visual Basic程序設計實驗指導(第4版)
- Microsoft Dynamics GP 2013 Reporting, Second Edition
- 人人都是網站分析師:從分析師的視角理解網站和解讀數據
- Protocol-Oriented Programming with Swift
- Rust游戲開發實戰
- Programming Microsoft Dynamics? NAV 2015
- Building Business Websites with Squarespace 7(Second Edition)
- Python預測分析與機器學習
- Android高級開發實戰:UI、NDK與安全
- Spring Boot從入門到實戰
- Apache Solr for Indexing Data