Skip to content

Instantly share code, notes, and snippets.

@lmiller1990
Created April 28, 2018 03:40
Show Gist options
  • Save lmiller1990/984a160fa70e798dba29329563cfe2c4 to your computer and use it in GitHub Desktop.
Save lmiller1990/984a160fa70e798dba29329563cfe2c4 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.16/vue.js"></script>
</head>
<body>
<div id="app">
</div>
</body>
<style>
.item {
height: 50px;
width: 50px;
border: 1px dashed black;
}
.game {
display: flex;
flex-wrap: wrap;
width: 160px;
}
</style>
<script>
new Vue({
el: '#app',
template: `
<div class="game">
<div v-on:click="setMark(idx)" v-for="(item, idx) in game" class="item">
{{ item }}
</div>
</div>`,
methods: {
setMark(idx) {
if (this.game[idx] != '') {
return
}
Vue.set(this.game, idx, this.currentPlayer)
if (this.currentPlayer == "X") {
this.currentPlayer = "O"
} else {
this.currentPlayer = "X"
}
}
},
data() {
return {
currentPlayer: "O",
game: new Array(9).fill('')
}
}
})
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment