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

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'],
})
主站蜘蛛池模板: 乌拉特前旗| 红原县| 宁波市| 德昌县| 赤水市| 大英县| 神木县| 西和县| 柳江县| 和林格尔县| 上虞市| 新巴尔虎左旗| 平定县| 万山特区| 綦江县| 甘孜| 东源县| 定兴县| 龙山县| 皋兰县| 青田县| 和硕县| 上犹县| 德昌县| 东乌珠穆沁旗| 邹平县| 来凤县| 桃园市| 大洼县| 蒙阴县| 青海省| 新平| 兴化市| 宁陵县| 思茅市| 仪陇县| 安丘市| 大冶市| 化州市| 衡南县| 西昌市|