-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add list of boats alive or dead #6
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<template> | ||
<div> | ||
<ol class="boats-liste"> | ||
<li | ||
v-for="boat in boatsInfos" | ||
:key="boat.name" | ||
v-bind:class="{sunk: boat.isSunk}" | ||
>{{boat.name}} ({{boat.nbCells}})</li> | ||
</ol> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
name: "Boats", | ||
props: { | ||
boats: { | ||
type: Object, | ||
required: true | ||
} | ||
}, | ||
computed: { | ||
boatsInfos: function() { | ||
const x = Object.keys(this.boats) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. x => boatsInformation ca me semble hyper compliqué quand l'objet passé en props a déjà quasiment toutes les infos, on veut forcément l'ordonner? |
||
.filter(name => !!this.boats[name].cells) | ||
.map(name => ({ | ||
name, | ||
nbCells: this.boats[name].cells.length, | ||
isSunk: this.boats[name].nbOfAliveCells === 0 | ||
})) | ||
.sort((boat1, boat2) => | ||
boat1.nbCells < boat2.nbCells || | ||
(boat1.nbCells === boat2.nbCells && boat1.name < boat2.name) | ||
? 1 | ||
: -1 | ||
); | ||
return x; | ||
} | ||
} | ||
}; | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
.sunk { | ||
text-decoration: line-through; | ||
color: red; | ||
} | ||
.boats-liste { | ||
list-style: none; | ||
padding: 100% 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pourquoi 100% ? |
||
margin: 0; | ||
font-size: 18px; | ||
font-weight: 500; | ||
} | ||
</style> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tu peux écrire ça
:class=
si tu veux 🙂https://v1.vuejs.org/guide/syntax.html#Shorthands