書名: Vue.js 2 Web Development Projects作者名: Guillaume Chau本章字數(shù): 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'],
})
推薦閱讀
- Docker技術(shù)入門與實戰(zhàn)(第3版)
- Rake Task Management Essentials
- Oracle 12c中文版數(shù)據(jù)庫管理、應(yīng)用與開發(fā)實踐教程 (清華電腦學(xué)堂)
- C語言程序設(shè)計實訓(xùn)教程
- Python零基礎(chǔ)快樂學(xué)習(xí)之旅(K12實戰(zhàn)訓(xùn)練)
- oreilly精品圖書:軟件開發(fā)者路線圖叢書(共8冊)
- Blender 3D Incredible Machines
- PySide GUI Application Development(Second Edition)
- Learning JavaScript Data Structures and Algorithms
- 程序設(shè)計基礎(chǔ)教程:C語言
- 輕松上手2D游戲開發(fā):Unity入門
- C語言程序設(shè)計習(xí)題與實驗指導(dǎo)
- Java編程從入門到精通
- PrimeFaces Blueprints
- Java Web應(yīng)用開發(fā)