- 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:

推薦閱讀
- Java逍遙游記
- Python程序設(shè)計教程(第2版)
- 在最好的年紀(jì)學(xué)Python:小學(xué)生趣味編程
- CockroachDB權(quán)威指南
- Java EE 6 企業(yè)級應(yīng)用開發(fā)教程
- Python入門很簡單
- 軟件測試工程師面試秘籍
- Visual Basic程序設(shè)計教程
- MATLAB定量決策五大類問題
- 大學(xué)計算機基礎(chǔ)(第2版)(微課版)
- OpenStack Orchestration
- 焊接機器人系統(tǒng)操作、編程與維護(hù)
- 領(lǐng)域驅(qū)動設(shè)計:軟件核心復(fù)雜性應(yīng)對之道(修訂版)
- Spring Security Essentials
- C# 10核心技術(shù)指南