- Vue.js 2 Web Development Projects
- Guillaume Chau
- 143字
- 2021-07-02 22:34:36
The castles
This one is actually pretty simple since it consists of only two images and a castle-banners component that will take care of the health and food display:
- In the world.js file, create a new castle component with two images that accepts a players and an index prop:
Vue.component('castle', {
template: `<p class="castle" :class="'player-' + index">
<img class="building" :src="'svg/castle' + index + '.svg'" />
<img class="ground" :src="'svg/ground' + index + '.svg'" />
<!-- Later, we will add a castle-banners component here -->
</p>`,
props: ['player', 'index'],
})
For this component, there is a castle and a ground image for each player; that means four images in total. For example, for the player at index 0, there are castle0.svg and the ground0.svg images.
- In the main template, just below the top-bar component, create a new p element with the world CSS class, loop over the players to display the two castles, and add another p element with the land class:
<p class="world">
<castle v-for="(player, index) in players" :player="player"
:index="index" />
<p class="land" />
</p>
In the browser, you should see one castle for each player, as follows:

推薦閱讀
- Kali Linux Web Penetration Testing Cookbook
- Learning ArcGIS Pro 2
- AngularJS深度剖析與最佳實踐
- Python Data Analysis(Second Edition)
- PySide GUI Application Development(Second Edition)
- Elasticsearch Server(Third Edition)
- Visual Foxpro 9.0數據庫程序設計教程
- Zabbix Performance Tuning
- Mastering Embedded Linux Programming
- Android編程權威指南(第4版)
- Python編程快速上手2
- Visual Basic語言程序設計上機指導與練習(第3版)
- Java EE 7 Development with WildFly
- Linux Networking Cookbook
- MonoTouch應用開發實踐指南:使用C#和.NET開發iOS應用