index.js
1.13 KB
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
import {
FETCH_HOME_REQUEST,
FETCH_HOME_FAILURE,
FETCH_HOME_SUCCESS
} from './types';
import {
HOME_CONTENT_CODE
} from '../content-code';
import _ from 'lodash';
export default {
state: {
home: {},
fethingHome: false
},
mutations: {
[FETCH_HOME_REQUEST](state) {
state.fethingHome = true;
},
[FETCH_HOME_FAILURE](state) {
state.fethingHome = false;
},
[FETCH_HOME_SUCCESS](state, {data}) {
state.fethingHome = false;
state.home = data;
},
},
actions: {
async [FETCH_HOME_REQUEST]({commit, state}) {
// if (!_.isEmpty(state.home)) {
// return Promise.resolve(state.home);
// }
commit(FETCH_HOME_REQUEST);
try {
const result = await this.$api.get('/resource/get', {content_code: HOME_CONTENT_CODE});
commit(FETCH_HOME_SUCCESS, result);
return result;
} catch (e) {
console.error(e);
commit(FETCH_HOME_FAILURE);
}
}
}
};