Skip to content

Commit 44b763a

Browse files
committed
use ternary operator in store/index.js
1 parent 6f8c669 commit 44b763a

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

src/store/index.js

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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
44

55
Vue.use(Vuex);
66
Vue.use(VueResource);
@@ -34,37 +34,36 @@ const mutations = {
3434

3535
const actions = {
3636
getData(context, object) {
37-
const {progress, isRefresh} = object;
37+
const { progress, isRefresh } = object;
38+
const mutationName = isRefresh === true ? "refreshData" : "addData";
3839
progress.$Progress.start();
39-
context.commit('updateLoadingState', false);
40-
context.commit('updateBusyState', true);
40+
context.commit("updateLoadingState", false);
41+
context.commit("updateBusyState", true);
4142

4243
/**
4344
* use vue-resource
4445
*/
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();
5357
}
54-
progress.$Progress.finish();
55-
}, () => {
56-
context.commit('updateBusyState', false);
57-
progress.$Progress.fail();
58-
});
59-
}
60-
58+
);
59+
},
6160
};
6261

6362
const store = new Vuex.Store({
64-
state,
65-
getters,
66-
mutations,
67-
actions,
63+
state,
64+
getters,
65+
mutations,
66+
actions,
6867
});
6968

7069
export default store;

0 commit comments

Comments
 (0)