Show error if no one w/ name found.

This commit is contained in:
2020-10-11 12:29:07 +02:00
committed by KevinMidboe
parent 1383a310b3
commit a59f1e2b17

View File

@@ -40,6 +40,10 @@
</div> </div>
</div> </div>
</section> </section>
<h2 v-else-if="error" class="error">
{{ error }}
</h2>
</div> </div>
</div> </div>
</template> </template>
@@ -58,7 +62,8 @@ export default {
}, },
data() { data() {
return { return {
winner: undefined winner: undefined,
error: undefined
} }
}, },
computed: { computed: {
@@ -66,6 +71,12 @@ export default {
return this.winner.highscore.length return this.winner.highscore.length
} }
}, },
created() {
const nameFromURL = this.$route.params.name;
getWinnerByName(nameFromURL)
.then(winner => this.setWinner(winner))
.catch(err => this.error = `Ingen med navn: "${nameFromURL}" funnet.`)
},
methods: { methods: {
setWinner(winner) { setWinner(winner) {
this.winner = winner this.winner = winner
@@ -94,11 +105,6 @@ export default {
}, },
humanReadableDate: humanReadableDate, humanReadableDate: humanReadableDate,
daysAgo: daysAgo daysAgo: daysAgo
},
created() {
const nameFromURL = this.$route.params.name;
if (this.winnerObject === undefined && nameFromURL !== null)
getWinnerByName(nameFromURL).then(winner => this.setWinner(winner))
} }
} }
</script> </script>