- Detect offline & online events for your vue app.
- Built from scratch usign Vue 2.7 with TypeScript
- For Vue >3.x version –
npm i v-offline@latest
- For Vue >=2.7 version –
npm i v-offline@legacy
- For Vue <2.7 version –
npm i v-offline@2.3.0
- vue
>^2.7
- @vue/composition-api
^1.x
npm install --save v-offline
CDN: UNPKG | jsDelivr (available as window.VOffline
)
# install dependencies
$ npm ci
# package the library
$ npm run build
Vue.component('VOffline', require('v-offline'));
import Vue from 'vue';
import VOffline from 'v-offline';
Vue.use(VOffline);
import { VOffline } from 'v-offline';
Locally imported as a component
<v-offline @detected-condition="amIOnline">
<template v-if="online"> ( Online: {{ onLine }} ) </template>
<template v-if="offline"> ( Online: {{ onLine }} ) </template>
</v-offline>
import { VOffline } from 'v-offline';
Vue.component('example-component', {
components: {
VOffline
},
data() {
return {
onLine: true,
};
},
methods: {
amIOnline(e) {
this.onLine = e;
},
},
});
.offline {
background-color: #fc9842;
background-image: linear-gradient(315deg, #fc9842 0%, #fe5f75 74%);
}
.online {
background-color: #00b712;
background-image: linear-gradient(315deg, #00b712 0%, #5aff15 74%);
}
Name | Type | Required? | Default | Description |
---|---|---|---|---|
online-class |
String | No | '' | Styling the div which you want to give if you're online. |
offline-class |
String | No | '' | Styling the div which you want to give if you're offline. |
ping-url |
String | No | https://google.com | Pinging any url to double check if you're online or not. |
Name | Returns | Description |
---|---|---|
@detected-condition |
String | Emits a boolean value |
- Fork it ( https://github.com/vinayakkulkarni/v-offline/fork )
- Create your feature branch (
git checkout -b feat/new-feature
) - Commit your changes (
git commit -Sam 'feat: add feature'
) - Push to the branch (
git push origin feat/new-feature
) - Create a new Pull Request
Note:
- Please contribute using Github Flow
- Commits & PRs will be allowed only if the commit messages & PR titles follow the conventional commit standard, read more about it here
- PS. Ensure your commits are signed. Read why
v-offline © Vinayak, Released under the MIT License.
Authored and maintained by Vinayak Kulkarni with help from contributors (list).
vinayakkulkarni.dev · GitHub @vinayakkulkarni · Twitter @_vinayak_k