Created
July 30, 2018 16:05
-
-
Save afontcu/29233c67f945da590be8f5e2c7c1163a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div> | |
<h1>Election day!</h1> | |
<button @click="voteForRed">Vote for 🔴</button> | |
<button @click="voteForBlue">Vote for 🔵</button> | |
<h2>Results</h2> | |
<results/> | |
<total-votes/> | |
</div> | |
</template> | |
<script> | |
const state = { | |
red: 0, | |
blue: 0, | |
} | |
const TotalVotes = { | |
data () { return state }, | |
render (h) { | |
return h('div', `Total votes: ${this.red + this.blue}`) | |
}, | |
} | |
const Results = { | |
data () { return state }, | |
render (h) { | |
return h('div', `Red: ${this.red} - Blue: ${this.blue}`) | |
}, | |
} | |
export default { | |
components: { TotalVotes, Results }, | |
data () { return state }, | |
methods: { | |
voteForRed () { this.red++ }, | |
voteForBlue () { this.blue++ }, | |
}, | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment