Created
September 25, 2018 05:52
-
-
Save oomusou/eac52dcdf580d275a774e188c6e647c2 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="todolist"> | |
<input type="text" v-model="input"> | |
<button @click="addTodo">Add</button> | |
<ul> | |
<li v-for="(item, index) in todos" @click="finishItem(index)" :key="index"> | |
{{ item.title }}, {{ item.completed }} | |
</li> | |
</ul> | |
</div> | |
</template> | |
<script> | |
import { mapActions, mapMutations, mapState } from 'vuex'; | |
const addTodo = function() { | |
this.addItem(this.input); | |
this.input = ''; | |
}; | |
const data = () => ({ | |
input: '', | |
}); | |
const computed = mapState('todolist', { | |
todos: state => state.todos, | |
}); | |
const methods = { | |
...mapMutations('todolist', ['finishItem', 'addItem']), | |
...mapActions('todolist', ['getTodos']), | |
addTodo, | |
}; | |
const mounted = function() { | |
this.getTodos(); | |
}; | |
export default { | |
name: 'todolist', | |
data, | |
computed, | |
methods, | |
mounted, | |
}; | |
</script> | |
<style scoped> | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment