Skip to content

Instantly share code, notes, and snippets.

@TitasGailius
Created March 23, 2018 17:55
Show Gist options
  • Save TitasGailius/40a5104384ae87ef486db898731292be to your computer and use it in GitHub Desktop.
Save TitasGailius/40a5104384ae87ef486db898731292be to your computer and use it in GitHub Desktop.
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