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

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'],
})
主站蜘蛛池模板: 湘阴县| 绥化市| 安新县| 兴隆县| 弥勒县| 新建县| 五峰| 延边| 罗源县| 华亭县| 东明县| 呈贡县| 嵊泗县| 重庆市| 阿拉善右旗| 满城县| 安阳市| 西安市| 思南县| 台北县| 武川县| 宁波市| 上蔡县| 石狮市| 曲阜市| 汝城县| 神农架林区| 贵定县| 子长县| 四川省| 龙州县| 濮阳县| 屯留县| 鱼台县| 凉城县| 乐山市| 新化县| 安徽省| 贵南县| 峨眉山市| 汝城县|