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

How to register global #71

Closed youtingkun closed 3 years ago

youtingkun commented 3 years ago

main.js

import Loading from 'vue-loading-overlay';
Vue.use(Loading);

example.vue

<template>
    <form @submit.prevent="submit" class="vld-parent" ref="formContainer">
        <!-- your form inputs goes here-->
        <label><input type="checkbox" v-model="fullPage" />Full page?</label>
        <button type="submit">Login</button>
    </form>
</template>

<script>
export default {
    data() {
        return {
            fullPage: false,
        };
    },
    methods: {
        submit() {
            let loader = this.$loading.show({
                // Optional parameters
                container: this.fullPage ? null : this.$refs.formContainer,
                canCancel: true,
                onCancel: this.onCancel,
            });
            // simulate AJAX
            setTimeout(() => {
                loader.hide();
            }, 5000);
        },
        onCancel() {
            console.log('User cancelled the loader.');
        },
    },
};
</script>

error:

vue.runtime.esm.js?2b0e:619 [Vue warn]: Error in v-on handler: "TypeError: this.$loading.show is not a function"
ankurk91 commented 3 years ago

Please fill the issue template and specifytthe versions.