Skip to content

Commit 3071394

Browse files
committed
Split out the new game functionality into a subcomponent.
1 parent 8bd5681 commit 3071394

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed

src/BoardAdd.vue

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<template>
2+
<div>
3+
<select v-model="type">
4+
<option value="dice">Board Game</option>
5+
<option value="spades">Card Game</option>
6+
</select>
7+
<input v-model="name" @keyup.enter="add">
8+
<button @click="add">Add</button>
9+
</div>
10+
</template>
11+
12+
<script>
13+
module.exports = {
14+
data: function() {
15+
return {
16+
name: '',
17+
type: 'dice',
18+
}
19+
},
20+
methods: {
21+
add: function () {
22+
this.$emit('add', {
23+
name: this.name,
24+
type: this.type
25+
})
26+
}
27+
}
28+
}
29+
</script>

src/BoardLibrary.vue

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
11
<template>
22
<div>
3-
<select v-model="type">
4-
<option value="dice">Board Game</option>
5-
<option value="spades">Card Game</option>
6-
</select>
7-
<input v-model="game" @keyup.enter="addGame">
8-
<button @click="addGame">Add</button>
3+
<board-add @add="handleAdd"></board-add>
94
<p v-if="empty">Zarro Boords!</p>
105
<ul v-else>
11-
<board-game v-for="g in games" :type="g.type" :name="g.game"></board-game>
6+
<board-game v-for="game in games" :type="game.type" :name="game.name"></board-game>
127
</ul>
138
</div>
149
</template>
1510

1611
<script>
12+
var BoardAdd = require('./BoardAdd.vue')
1713
var BoardGame = require('./BoardGame.vue')
1814
1915
module.exports = {
2016
data: function() {
2117
return {
22-
game: '',
23-
type: 'dice',
2418
games: []
2519
}
2620
},
@@ -30,14 +24,12 @@ module.exports = {
3024
}
3125
},
3226
methods: {
33-
addGame: function () {
34-
this.games.push({
35-
game: this.game,
36-
type: this.type
37-
})
27+
handleAdd: function (game) {
28+
this.games.push(game)
3829
}
3930
},
4031
components: {
32+
BoardAdd: BoardAdd,
4133
BoardGame: BoardGame
4234
}
4335
}

0 commit comments

Comments
 (0)