Skip to content

Instantly share code, notes, and snippets.

@yutakahashi114
Last active September 29, 2019 12:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yutakahashi114/2053a2d3d9ad5e918b8ed8215a4e8e42 to your computer and use it in GitHub Desktop.
Save yutakahashi114/2053a2d3d9ad5e918b8ed8215a4e8e42 to your computer and use it in GitHub Desktop.
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