ankurk91 / vue-loading-overlay

Vue.js component for full screen loading indicator :cyclone:
https://ankurk91.github.io/vue-loading-overlay/
MIT License
1.25k stars 102 forks source link

Using vue-loading within vuex store #38

Closed nezaboravi closed 5 years ago

nezaboravi commented 5 years ago

Hi, Adding vue-loading in store wont work. When i add it inside component, al works.

My bootstrap file:

import Loading from 'vue-loading-overlay';
import 'vue-loading-overlay/dist/vue-loading.css';

Vue.use(Loading);
Vue.use(VueNoty);
Vue.use(Vuex);

Here is the current code- inside store/index.js

    actions: {
        setAds({ commit }, category) {
            let loader = this.$loading.show({
                // Optional parameters
                loader: 'dots',
                height: 255,
                width: 255,
                color: '#7DC242'
            });
            axios.get('/ads', { params: { category: category } }).then(data => {
                let ads = data.data.data;
                commit('ads', ads);
                loader.hide()
            });
        },

Here is the error photo:

Screenshot 2019-11-18 16 30 02
ankurk91 commented 5 years ago

I don't think this refers to a Vue instance here, you can import vue and can use it like

// in your vuex store
import Vue from 'vue;

Vue.$loading.show({})
nezaboravi commented 5 years ago

Just Vue.$loading works, no need to import Vue in store. Thanks