vuesax icon indicating copy to clipboard operation
vuesax copied to clipboard

vuesax prototype loading doesn't work outside of components

Open guirociozanini opened this issue 5 years ago • 11 comments

Using vuesax 3.11.7 version.

Hello, I updated my vuesax from version 3.9.0 to 3.11.7 and now i can't use the loading function outside of vue components.

Example:

This works:

export default {
  methods:{
    openLoading(){
      this.$vs.loading()
      setTimeout( ()=> {
        this.$vs.loading.close()
      }, 2000);
    },
  }
}

This doesn't work:

axios.interceptors.response.use(response => {
        Vue.prototype.$vs.loading.close()
    return response
})

does anyone have any idea how to fix?

guirociozanini avatar Jan 13 '20 17:01 guirociozanini

I was digging more deeper and found this PR #701 , but I can't see how to control the loading component now.

guirociozanini avatar Jan 13 '20 19:01 guirociozanini

any news?

garbinmarcelo avatar Jul 13 '20 20:07 garbinmarcelo

Yes, I gave up on vuesax.

guirociozanini avatar Jul 14 '20 23:07 guirociozanini

Yes, I gave up on vuesax.

what are you using?

garbinmarcelo avatar Jul 15 '20 13:07 garbinmarcelo

Vuetify, the best framework for Vue in my opinion

guirociozanini avatar Jul 15 '20 15:07 guirociozanini

After hours trying to make this component work, i gave up

samhk222 avatar Jul 31 '20 06:07 samhk222

My solution was to export the function to prototype again, and did work, but I don't have the code anymore :(

guirociozanini avatar Jul 31 '20 14:07 guirociozanini

@Keilost don't know how to do this ...

My solution, althought it's no beautiful, was to call the close inside a timeout ...

                 this.$vs.loading({
                    background: this.backgroundLoading,
                    color: this.colorLoading,
                    container: "#button-with-loading",
                    scale: 0.45,
                });

                .......

                setTimeout(() => {
                    this.$vs.loading.close("#button-with-loading > .con-vs-loading");
                }, 1);```

samhk222 avatar Aug 04 '20 00:08 samhk222

Although not pretty, my current workaround was to add $vs back to the prototype.

Vue.prototype.$vs = this.$vs;

christopherchristensen avatar Sep 01 '20 10:09 christopherchristensen

As I can see you are trying to use $vs in a js file when you set up axios interceptor to take care of the loading indicator automatically. I solved the issue as I set up a watcher in my main.vue for the isLoading boolean stored in Vuex store. In the watcher the this.$vs is available for you to open the loader when an axios request is on the fly. In the axios interceptor js file, you can just simply commit startLoading and stopLoading actions, which will take care of setting up the isLoading state for you.

kelemenbalazs avatar Nov 30 '20 19:11 kelemenbalazs

@Keilost don't know how to do this ...

My solution, althought it's no beautiful, was to call the close inside a timeout ...

                 this.$vs.loading({
                    background: this.backgroundLoading,
                    color: this.colorLoading,
                    container: "#button-with-loading",
                    scale: 0.45,
                });

                .......

                setTimeout(() => {
                    this.$vs.loading.close("#button-with-loading > .con-vs-loading");
                }, 1);```

Worked for me :)

setTimeout(() => {
                this.$vs.loading.close("#loading");
            }, 1);

andyslack avatar Sep 08 '21 14:09 andyslack