|
1 |
| -import Vue from 'vue'; // get vue |
2 |
| -import Vuex from 'vuex'; // get vuex |
3 |
| -import VueResource from 'vue-resource';// get $http |
| 1 | +import Vue from "vue"; // get vue |
| 2 | +import Vuex from "vuex"; // get vuex |
| 3 | +import VueResource from "vue-resource"; // get $http |
4 | 4 |
|
5 | 5 | Vue.use(Vuex);
|
6 | 6 | Vue.use(VueResource);
|
@@ -34,37 +34,36 @@ const mutations = {
|
34 | 34 |
|
35 | 35 | const actions = {
|
36 | 36 | getData(context, object) {
|
37 |
| - const {progress, isRefresh} = object; |
| 37 | + const { progress, isRefresh } = object; |
| 38 | + const mutationName = isRefresh === true ? "refreshData" : "addData"; |
38 | 39 | progress.$Progress.start();
|
39 |
| - context.commit('updateLoadingState', false); |
40 |
| - context.commit('updateBusyState', true); |
| 40 | + context.commit("updateLoadingState", false); |
| 41 | + context.commit("updateBusyState", true); |
41 | 42 |
|
42 | 43 | /**
|
43 | 44 | * use vue-resource
|
44 | 45 | */
|
45 |
| - Vue.http.get('/mock/api.json').then((response) => { |
46 |
| - const json = response.data; |
47 |
| - context.commit('updateLoadingState', true); |
48 |
| - context.commit('updateBusyState', false); |
49 |
| - if (isRefresh === true) { |
50 |
| - context.commit('refreshData', json); |
51 |
| - } else { |
52 |
| - context.commit('addData', json); |
| 46 | + Vue.http.get("/mock/api.json").then( |
| 47 | + (response) => { |
| 48 | + const json = response.data; |
| 49 | + context.commit("updateLoadingState", true); |
| 50 | + context.commit("updateBusyState", false); |
| 51 | + context.commit(mutationName, json); |
| 52 | + progress.$Progress.finish(); |
| 53 | + }, |
| 54 | + () => { |
| 55 | + context.commit("updateBusyState", false); |
| 56 | + progress.$Progress.fail(); |
53 | 57 | }
|
54 |
| - progress.$Progress.finish(); |
55 |
| - }, () => { |
56 |
| - context.commit('updateBusyState', false); |
57 |
| - progress.$Progress.fail(); |
58 |
| - }); |
59 |
| -} |
60 |
| - |
| 58 | + ); |
| 59 | + }, |
61 | 60 | };
|
62 | 61 |
|
63 | 62 | const store = new Vuex.Store({
|
64 |
| - state, |
65 |
| - getters, |
66 |
| - mutations, |
67 |
| - actions, |
| 63 | + state, |
| 64 | + getters, |
| 65 | + mutations, |
| 66 | + actions, |
68 | 67 | });
|
69 | 68 |
|
70 | 69 | export default store;
|
0 commit comments