-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathexample-module.js
61 lines (57 loc) · 1.2 KB
/
example-module.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
import { fetchCustomer } from '@/api';
export const types = {
INDEX: {
REQUEST: 'CUSTOMER_GROUPS/INDEX_REQUEST',
SUCCESS: 'CUSTOMER_GROUPS/INDEX_SUCCESS',
FAILURE: 'CUSTOMER_GROUPS/INDEX_FAILURE'
}
};
export const customerState = {
list: {
isLoading: false,
isLoaded: false,
data: [],
errors: {}
}
};
export const mutations = {
[types.INDEX.REQUEST](state) {
state.list = {
...state.list,
isLoading: true,
errors: {}
};
},
[types.INDEX.SUCCESS](state, payload) {
state.list = {
isLoading: false,
isLoaded: true,
data: payload.data,
errors: {}
};
},
[types.INDEX.FAILURE](state, payload) {
state.list = {
isLoading: false,
isLoaded: false,
data: [],
errors: payload.error
};
}
};
export default {
state: customerState,
getters,
mutations,
actions: {
async fetchCustomer({ commit }) {
commit({ type: types.INDEX.REQUEST });
try {
const res = await fetchCustomer();
commit({ type: types.INDEX.SUCCESS, payload: { data: res.data } });
} catch (error) {
commit({ type: types.INDEX.FAILURE, payload: { error } });
}
}
}
};