Last active
September 29, 2019 12:30
-
-
Save yutakahashi114/2053a2d3d9ad5e918b8ed8215a4e8e42 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 axios from 'axios'; | |
export const state = () => ({ | |
users: [] | |
}) | |
export const mutations = { | |
setUsers(state, users) { | |
state.users = users; | |
} | |
} | |
export const actions = { | |
async getAllUsers(context) { | |
try { | |
const { data } = await axios.get('/api/users') | |
context.commit('setUsers', data) | |
} catch (error) { | |
console.log(error) | |
} | |
}, | |
async addUser(context, params) { | |
try { | |
await axios.post('/api/users', params) | |
} catch (error) { | |
console.log(error) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment