-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApiSample.js
80 lines (78 loc) · 1.85 KB
/
ApiSample.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import Vue from 'vue'
import Vuex from 'vuex'
import Axios from 'axios'
import VueAxios from 'vue-axios'
import Api from '../services/Api'
Vue.use(Vuex)
Vue.use(VueAxios, Axios)
export default new Vuex.Store(
{
state:
{
user:
{
name:"",
surname:"",
email:"",
role:"-1",
token:"",
},
agricultures:[],
fields:[]
},
getters:
{
SURNAME: state => { return state.user.surname; },
NAME: state => { return state.user.name; },
EMAIL: state => { return state.user.email; },
ROLE: state => { return state.user.role; },
TOKEN: state => { return state.user.token; }
},
mutations:
{
SET_SURNAME: (state, surname) => { state.user.surname = surname; },
SET_NAME: (state, name) => { state.user.name = name; },
SET_EMAIL: (state, email) => { state.user.email = email; },
SET_ROLE: (state, role) => { state.user.role = role; },
SET_TOKEN: (state, token) => { state.user.token = token; }
},
actions:
{
LOGIN: async (context, data) =>
{
await Api().post('/user-login', data)
.then(response =>
{
context.commit('SET_SURNAME', response.data.surname);
context.commit('SET_NAME', response.data.name);
context.commit('SET_EMAIL', response.data.email);
context.commit('SET_ROLE', response.data.role);
context.commit('SET_TOKEN', response.data.token);
})
.catch(error =>
{
console.log(error.response)
});
},
SIGNUP: async (context, data) =>
{
await Api().post('/user-signup', data)
.then(response =>
{
context.commit('SET_SURNAME', response.data.surname);
context.commit('SET_NAME', response.data.name);
context.commit('SET_EMAIL', response.data.email);
context.commit('SET_ROLE', response.data.role);
context.commit('SET_TOKEN', response.data.token);
})
.catch(error =>
{
console.log(error.response)
});
}
},
modules:
{
},
strict: true
})