- 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>
推薦閱讀
- Data Visualization with D3 4.x Cookbook(Second Edition)
- Java Web程序設計
- 程序員修煉之道:通向務實的最高境界(第2版)
- 高級語言程序設計(C語言版):基于計算思維能力培養
- 深入分布式緩存:從原理到實踐
- NGINX Cookbook
- Unity 2018 Shaders and Effects Cookbook
- 21天學通C++(第5版)
- Learning Modular Java Programming
- Spring Boot+MVC實戰指南
- C++程序設計教程(第2版)
- 現代C:概念剖析和編程實踐
- C語言程序設計
- Visual Basic 程序設計實踐教程
- Learning IBM Bluemix