Created
March 23, 2018 17:55
-
-
Save TitasGailius/40a5104384ae87ef486db898731292be to your computer and use it in GitHub Desktop.
This file contains hidden or 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, { StoreOptions } from "vuex" | |
import { RootState, Todo } from "../types/store"; | |
import axios from "axios" | |
Vue.use(Vuex) | |
export default new Vuex.Store({ | |
state: { | |
todos: [] | |
}, | |
actions: { | |
async fetchTodos({ commit }) { | |
return commit('setTodos', await axios.get('/api/todos')) | |
} | |
}, | |
mutations: { | |
setTodos(state: RootState, todos: Todo[]) { | |
state.todos = todos | |
} | |
} | |
} as StoreOptions<RootState>) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment