Created
September 14, 2018 02:11
-
-
Save oomusou/8ba38828cefd922cbc08f26a6c9486c7 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 axios from 'axios'; | |
Vue.use(Vuex); | |
const state = { | |
count: 0, | |
todos: [], | |
}; | |
const mutations = { | |
setTodos: (state, payload) => state.todos = payload, | |
addItem: (state, payload) => state.todos.push({ title: payload, completed: false }), | |
finishItem: (state, payload) => state.todos[payload].completed = !state.todos[payload].completed, | |
}; | |
const actions = { | |
fetchTodos({ commit }) { | |
const endpoint = 'https://jsonplaceholder.typicode.com/todos'; | |
const response = res => commit('setTodos', res.data.slice(0, 5)); | |
const error = e => console.log(e); | |
axios | |
.get(endpoint) | |
.then(response) | |
.catch(error); | |
}, | |
}; | |
export default { | |
state, | |
mutations, | |
actions, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment