Vue Loading Overlay Component
Vue.js v2.x component for full screen loading indicator
Installation
:mega: Now published to npm
npm install vue-loading-overlay --save
yarn add vue-loading-overlay
Usage
As component
<template>
<div>
<loading :active.sync="isSaving" :can-cancel="true"></loading>
</div>
</template>
<script>
import Loading from 'vue-loading-overlay';
import 'vue-loading-overlay/dist/vue-loading.min';
export default {
data() {
return {
isSaving: false,
}
},
components: {
Loading
},
methods: {
submit() {
this.isSaving = true;
}
}
}
</script>
As plugin
<template>
<form @submit.prevent="submit">
</form>
</template>
<script>
import Vue from 'vue';
import Loading from 'vue-loading-overlay';
import 'vue-loading-overlay/dist/vue-loading.min';
Vue.use(Loading);
export default {
methods: {
submit() {
let loader = this.$loading.show();
axios.post('/api').then((response)=>{
loader.hide()
})
}
}
}
</script>
Available props
The component accepts these props:
Attribute | Type | Default | Description |
---|
canCancel | Boolean | false | Allow user to cancel |
onCancel | Function | ()=>{} | Do something upon cancel |
Install in non-module environments (without webpack)
<script src="https://unpkg.com/vue@2.5/dist/vue.min.js"></script>
<script src="https://unpkg.com/vue-loading-overlay@2"></script>
<link rel="stylesheet" href="https://unpkg.com/vue-loading-overlay@latest/dist/vue-loading.min.css">
<script>
Vue.use(VueLoading)
</script>
Run examples on your localhost
- Clone this repo
- Make sure you have node-js >=6.10 and yarn >=1.x pre-installed
- Install dependencies -
yarn install
- Run webpack dev server -
yarn start
- This should open the demo page at
http://localhost:8000
in your default web browser
Credits
License
MIT License