Created
September 25, 2018 05:53
-
-
Save oomusou/642b4d613e44e881872ad71684ebbd63 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
import Vue from 'vue'; | |
import Vuex from 'vuex'; | |
import todoApi from '../../api/todosApi'; | |
Vue.use(Vuex); | |
const setTodos = (state, payload) => state.todos = payload; | |
const addItem = (state, payload) => | |
state.todos.push({ title: payload, completed: false }); | |
const finishItem = (state, payload) => | |
state.todos[payload].completed = !state.todos[payload].completed; | |
const error = e => console.log(e); | |
const response = commit => | |
res => commit('setTodos', res.data.slice(0, 5)); | |
const getTodos = ({ commit }) => | |
todoApi | |
.fetchTodos() | |
.then(response(commit)) | |
.catch(error); | |
const state = { | |
todos: [], | |
}; | |
const mutations = { | |
setTodos, | |
addItem, | |
finishItem, | |
}; | |
const actions = { | |
getTodos, | |
}; | |
export default { | |
namespaced: true, | |
state, | |
mutations, | |
actions, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment