Created
September 13, 2018 08:31
-
-
Save oomusou/50f04855bec025d809eece369b964977 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 id="app"> | |
<input type="text" v-model="input"><button @click="addItem">Add</button> | |
<ul> | |
<li v-for="(item, index) in todos" @click="finishItem(index)" :key="index"> | |
{{ item.task }}, {{ item.done }} | |
</li> | |
</ul> | |
<h2>Not done : {{ itemsNotDone }}</h2> | |
<h2>Done : {{ itemsDone }}</h2> | |
<h2>Task : {{ taskByIndex(index) }}</h2> | |
</div> | |
</template> | |
<script> | |
import { mapState, mapGetters } from 'vuex'; | |
export default { | |
name: 'app', | |
data() { | |
return { | |
input: '', | |
index: 0, | |
}; | |
}, | |
computed: { | |
...mapState(['todos']), | |
...mapGetters(['itemsNotDone', 'itemsDone', 'taskByIndex']), | |
}, | |
methods: { | |
addItem() { | |
this.$store.commit('addItem', this.input); | |
this.input = ''; | |
}, | |
finishItem(index) { | |
this.$store.commit('finishItem', index); | |
this.index = index; | |
}, | |
}, | |
}; | |
</script> | |
<style> | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment