- 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>
推薦閱讀
- Cocos2D-X權威指南(第2版)
- 少年輕松趣編程:用Scratch創作自己的小游戲
- 程序員面試算法寶典
- Apache Hive Essentials
- Learn Programming in Python with Cody Jackson
- Python程序設計案例教程
- Symfony2 Essentials
- Arduino家居安全系統構建實戰
- 速學Python:程序設計從入門到進階
- Django 3.0入門與實踐
- Django實戰:Python Web典型模塊與項目開發
- 軟件體系結構
- 深入解析Java編譯器:源碼剖析與實例詳解
- 數據分析與挖掘算法:Python實戰
- Getting Started with React VR