ankurk91 / vue-loading-overlay

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

Add support to custom loaders? #40

Closed niightly closed 4 years ago

niightly commented 4 years ago

do you have or intend to add support to custom loaders instead of the 3 predefined?

I have one on my own, and I want to use it instead of dots, spinners and things like that.

ankurk91 commented 4 years ago

This is documented here https://github.com/ankurk91/vue-loading-overlay#vueloadingshowpropsdataslots

// Pass slots by their names
  default: this.$createElement('your-custom-loader-component-name'),

You can find the working example in examples folder as well.

chris commented 4 years ago

This may be obvious to others with more Vue experience than me. Also, I'm using Nuxt, which may mean this is a bit different. But here's how I did it:

  1. Create a new component that is some SVG you want for your loader. In my case it was a fully custom animation and graphic in the SVG, so I didn't need any custom props. e.g. in a LogoLoader.vue file:

    <template>
      <svg ...>
    </template>
    
    <script>
    export default {
      name: 'Logo',
    }
    </script>
  2. Add the component in the page/template I was using it on:

    import LogoLoader from '~/components/LogoLoader.vue'
    
    export default {
      components: {
        Loader,
        LogoLoader,
      }
    }
  3. Specify the custom loader via slot, in component use:

    <loading
      :active.sync="isLoading"
      :is-full-page="loader.fullPage"
    >
      <LogoLoader />
    </loading>