forked from TIGERB/easy-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
store.js
110 lines (97 loc) · 2.6 KB
/
store.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import Vue from 'vue'; // get vue
import Vuex from 'vuex'; // get vuex
import VueResource from 'vue-resource';// get $http
Vue.use(Vuex);
Vue.use(VueResource);
var state = {
cardData: [],
isloadingComplete: false,
busy: false,
isShow: false,
test: [
'Youth is not a time of life; it is a state of mind; it is not a matter of rosy cheeks, red lips and supple knees; it is a matter of the will, a quality of the imagination, a vigor of the emotions; it is the freshness of the deep springs of life' + + Math.random()*100000000000,
]
};
var getters = {
}
var mutations = {
updateLoadingState(state, data){
state.isloadingComplete = data;
},
updateBusyState(state, data){
state.busy = data;
},
addData(state, data){
state.cardData = state.cardData.concat(data);
},
refreshData(state, data){
state.cardData = data;
},
isShowAlert(state, data){
state.isShow = data;
}
};
var actions = {
getData(context, object){
var progress = object.progress;
var isRefresh = object.refresh;
progress.$Progress.start();
context.commit('updateLoadingState', false);
context.commit('updateBusyState', true);
/**
* use vue-resource
*/
Vue.http.get('/api.json').then(response => {
var json = response.data;
context.commit('updateLoadingState', true);
context.commit('updateBusyState', false);
if (isRefresh === true) {
context.commit('refreshData', json);
}else {
context.commit('addData', json);
}
progress.$Progress.finish();
}, response => {
context.commit('updateBusyState', false);
progress.$Progress.fail();
});
/**
* use fetch
*/
// fetch('/api.json')
// .then(function(response) {
// return response.json();
// }).then(function(json) {
// console.log(this.state.cardData);
// context.commit('updateLoadingState', true);
// context.commit('updateBusyState', false);
// if (isRefresh === true) {
// context.commit('refreshData', json);
// }else {
// context.commit('addData', json);
// }
// progress.$Progress.finish();
// }).catch(function(error) {
// context.commit('updateBusyState', false);
// progress.$Progress.fail();
// });
}
};
var moduleCard = {
state: state,
getters: getters,
mutations: mutations,
actions: actions
};
var store = new Vuex.Store({
state: state,
getters: getters,
mutations: mutations,
actions: actions
});
module.exports = store;
// export default new Vuex.Store({
// modules: {
// moduleCard: moduleCard
// }
// });