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

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'],
})
主站蜘蛛池模板: 区。| 瓮安县| 龙州县| 朝阳市| 万宁市| 大荔县| 密云县| 上林县| 新河县| 大余县| 阆中市| 巫溪县| 南平市| 鞍山市| 兴城市| 耒阳市| 弥渡县| 遂川县| 新竹市| 娱乐| 轮台县| 施甸县| 鄱阳县| 称多县| 新干县| 醴陵市| 昌宁县| 壶关县| 区。| 通榆县| 凉山| 科技| 扬中市| 万源市| 汾阳市| 弋阳县| 育儿| 江达县| 石嘴山市| 额尔古纳市| 苏州市|