Skip to content

Commit 1a46dd1

Browse files
committed
Refactor to use computed properties and methods.
1 parent c5b6475 commit 1a46dd1

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

index.html

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
<body>
99
<div id="app">
1010
<select v-model="type">
11-
<option value="icon-dice">Board Game</option>
12-
<option value="icon-spades">Card Game</option>
11+
<option value="dice">Board Game</option>
12+
<option value="spades">Card Game</option>
1313
</select>
14-
<input v-model="game">
15-
<button @click="games.push({game: game, type: type})">Add</button>
16-
<p v-if="games.length == 0">Zarro Boords!</p>
14+
<input v-model="game" @keyup.enter="addGame">
15+
<button @click="addGame">Add</button>
16+
<p v-if="empty">Zarro Boords!</p>
1717
<ul v-else>
1818
<li v-for="g in games">
19-
<span :class="g.type"></span>
19+
<span :class="icon(g.type)"></span>
2020
{{ g.game }}
2121
</li>
2222
</ul>
@@ -27,8 +27,24 @@
2727
el: '#app',
2828
data: {
2929
game: '',
30-
type: 'icon-dice',
30+
type: 'dice',
3131
games: []
32+
},
33+
computed: {
34+
empty: function() {
35+
return this.games.length == 0
36+
}
37+
},
38+
methods: {
39+
addGame: function () {
40+
this.games.push({
41+
game: this.game,
42+
type: this.type
43+
})
44+
},
45+
icon: function (type) {
46+
return 'icon-' + type
47+
}
3248
}
3349
})
3450
</script>

0 commit comments

Comments
 (0)