- Vue.js 2 Web Development Projects
- Guillaume Chau
- 129字
- 2021-07-02 22:34:36
Castle banners
The castle banners will display the health and food for the castle. There will be two components inside the castle-banners component:
- A vertical banner whose height changes, depending of the amount of the stat
- A bubble with the actual number displayed
It will look like this:

- First, create a new castle-banners component with only the stat icons and a player prop:
Vue.component('castle-banners', {
template: `<p class="banners">
<!-- Food -->
<img class="food-icon" src="svg/food-icon.svg" />
<!-- Bubble here -->
<!-- Banner bar here -->
<!-- Health -->
<img class="health-icon" src="svg/health-icon.svg" />
<!-- Bubble here -->
<!-- Banner bar here -->
</p>`,
props: ['player'],
})
- We also need two computed properties that calculate the health and food ratios:
computed: {
foodRatio () {
return this.player.food / maxFood
},
healthRatio () {
return this.player.health / maxHealth
},
}
The maxFood and maxHealth variables are defined at the beginning of the state.js file.
- In the castle component, add the new castle-banners component:
template: `<p class="castle" :class="'player-' + index">
<img class="building" :src="'svg/castle' + index + '.svg'" />
<img class="ground" :src="'svg/ground' + index + '.svg'" />
<castle-banners :player="player" />
</p>`,
推薦閱讀
- INSTANT Mock Testing with PowerMock
- R語言經典實例(原書第2版)
- MATLAB應用與實驗教程
- SQL語言從入門到精通
- 零基礎學Java(第4版)
- 軟件測試技術指南
- Protocol-Oriented Programming with Swift
- Unity 2018 Shaders and Effects Cookbook
- .NET Standard 2.0 Cookbook
- Java程序設計及應用開發
- Spring Boot 2+Thymeleaf企業應用實戰
- Python 3.6從入門到精通(視頻教學版)
- Tkinter GUI Application Development Blueprints
- Building Microservices with .NET Core 2.0(Second Edition)
- Python數據分析與挖掘實戰(第2版)