Skip to content

Instantly share code, notes, and snippets.

@sanath-kumar
Last active July 22, 2018 15:27
Show Gist options
  • Save sanath-kumar/e5daee3500a005e4665b19232ba09bf7 to your computer and use it in GitHub Desktop.
Save sanath-kumar/e5daee3500a005e4665b19232ba09bf7 to your computer and use it in GitHub Desktop.
import Vue from 'vue'
import Vuex from 'vuex'
import Axios from 'axios'
Vue.use(Vuex);
export const store = new Vuex.Store({
state: {
todos : null
},
getters : {
TODOS : state => {
return state.todos;
}
},
mutations: {
SET_TODO : (state,payload) => {
state.todos = payload
},
ADD_TODO : (state,payload) => {
state.todos.push(payload)
},
},
actions:{
GET_TODO : async (context,payload) => {
let { data } = await Axios.get('http://yourwebsite.com/api/todo')
context.commit('SET_TODO',data)
},
SAVE_TODO : async (context,payload) => {
let { data } = await Axios.post('http://yourwebsite.com/api/todo')
context.commit('ADD_TODO',payload)
},
},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment