- Vue.js 2 Web Development Projects
- Guillaume Chau
- 115字
- 2021-07-02 22:34:35
The 'game over' overlay
For this one, we will create another component called player-result that will show whether a player is victorious or defeated. We will display the name of the player passed with a prop. We will compute the result for this player with a computed property, which we will also use as a dynamic CSS class:
Vue.component('player-result', {
template: `<p class="player-result" :class="result">
<span class="name">{{ player.name }}</span> is
<span class="result">{{ result }}</span>
</p>`,
props: ['player'],
computed: {
result () {
return this.player.dead ? 'defeated' : 'victorious'
},
},
})
Now, we can create the game over overlay by looping over the players props and using the player-result component:
Vue.component('overlay-content-game-over', {
template: `<p>
<p class="big">Game Over</p>
<player-result v-for="player in players" :player="player" />
</p>`,
props: ['players'],
})
推薦閱讀
- C# 7 and .NET Core Cookbook
- Android項目開發入門教程
- Oracle Database In-Memory(架構與實踐)
- Three.js開發指南:基于WebGL和HTML5在網頁上渲染3D圖形和動畫(原書第3版)
- 網店設計看這本就夠了
- Linux Device Drivers Development
- 飛槳PaddlePaddle深度學習實戰
- Getting Started with Laravel 4
- WordPress 4.0 Site Blueprints(Second Edition)
- Mastering Web Application Development with AngularJS
- Python:Deeper Insights into Machine Learning
- Getting Started with React VR
- Learning Concurrency in Python
- Web開發的平民英雄:PHP+MySQL
- JBoss AS 7 Development