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

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'],
})
主站蜘蛛池模板: 库尔勒市| 孝感市| 张家口市| 博客| 乌审旗| 苏尼特右旗| 苍梧县| 宣汉县| 平远县| 苍山县| 酒泉市| 和顺县| 观塘区| 民县| 松原市| 凤庆县| 广东省| 固始县| 西乌珠穆沁旗| 马鞍山市| 南投县| 兴业县| 绍兴市| 汉源县| 兰坪| 沂水县| 广河县| 延寿县| 乐陵市| 乡城县| 博客| 新乡县| 叶城县| 阿尔山市| 阳江市| 吉安市| 新兴县| 将乐县| 双牌县| 内黄县| 临清市|