Skip to content

Instantly share code, notes, and snippets.

@sanath-kumar
Last active November 1, 2019 07:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save sanath-kumar/5bd0e3dd1fa9a64e58f00fa0a92104d4 to your computer and use it in GitHub Desktop.
Save sanath-kumar/5bd0e3dd1fa9a64e58f00fa0a92104d4 to your computer and use it in GitHub Desktop.
import Axios from 'axios'
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)
}
}
export default {
state,getters,mutations,actions
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment