官术网_书友最值得收藏!

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'],
})
主站蜘蛛池模板: 巩义市| 舞钢市| 彰化市| 南汇区| 潮州市| 雅安市| 尼勒克县| 安塞县| 肃南| 林口县| 灵山县| 昌江| 牡丹江市| 肥西县| 商城县| 兴安县| 广水市| 万安县| 尤溪县| 太原市| 沈阳市| 怀仁县| 依兰县| 东台市| 阿拉善盟| 五台县| 玉屏| 彭阳县| 山丹县| 改则县| 五莲县| 黔东| 华蓥市| 曲阳县| 卢湾区| 佛教| 巫山县| 宝应县| 杂多县| 金堂县| 岫岩|