parsley/app/javascript/lib/GlobalMixins.js

26 lines
468 B
JavaScript
Raw Normal View History

2018-03-30 14:31:09 -05:00
import Vue from 'vue';
import { mapMutations, mapState } from 'vuex';
Vue.mixin({
computed: {
...mapState({
isLoading: state => state.loading
})
},
methods: {
...mapMutations([
'setError',
'setLoading'
]),
loadResource(promise, successFunc) {
this.setLoading(true);
return promise
.then(successFunc)
.catch(err => this.setError(err))
.then(() => this.setLoading(false));
}
}
});