Skip to content

Instantly share code, notes, and snippets.

@oomusou
Created September 25, 2018 05:52
Show Gist options
  • Save oomusou/eac52dcdf580d275a774e188c6e647c2 to your computer and use it in GitHub Desktop.
Save oomusou/eac52dcdf580d275a774e188c6e647c2 to your computer and use it in GitHub Desktop.
<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