Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. import axios from 'axios';
  2.  
  3. export const state = () => ({
  4. users: []
  5. })
  6.  
  7. export const mutations = {
  8. setUsers(state, users) {
  9. state.users = users;
  10. }
  11. }
  12.  
  13. export const actions = {
  14. async getAllUsers(context) {
  15. try {
  16. const { data } = await axios.get('/api/users')
  17. context.commit('setUsers', data)
  18. } catch (error) {
  19. console.log(error)
  20. }
  21. },
  22. async addUser(context, params) {
  23. try {
  24. await axios.post('/api/users', params)
  25. } catch (error) {
  26. console.log(error)
  27. }
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement