- 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'],
})
推薦閱讀
- JBoss Weld CDI for Java Platform
- INSTANT OpenCV Starter
- Vue.js 2 and Bootstrap 4 Web Development
- 軟件測試工程師面試秘籍
- Learning Bayesian Models with R
- Data Analysis with IBM SPSS Statistics
- Visual Basic程序設(shè)計(jì)實(shí)驗(yàn)指導(dǎo)(第4版)
- C程序設(shè)計(jì)實(shí)踐教程
- HTML5秘籍(第2版)
- 從零開始:UI圖標(biāo)設(shè)計(jì)與制作(第3版)
- 深度學(xué)習(xí)原理與PyTorch實(shí)戰(zhàn)(第2版)
- 編程改變生活:用Python提升你的能力(進(jìn)階篇·微課視頻版)
- Learning Bootstrap 4(Second Edition)
- Practical Predictive Analytics
- MongoDB Cookbook