Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vue-offline

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue-offline

Online/Offline events and directives for vue application

  • 1.0.201
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.9K
increased by7.06%
Maintainers
1
Weekly downloads
 
Created
Source

License: MIT

Offline/online states for Vue applications

This plugins notifies your application when online/offline status changes and allows to conditionally display components depending on the network status. Supports SSR.

Installation

There are two ways to install this plugin: Global - if you register the plugin globally all features will be immediately avvailable in all of your components

npm install vue-offline --save
import Vue from 'vue'
import VueOffline from 'vue-offline'

Vue.use(VueOffline)

Local for specific components - if you need online/offline features only in specific components you can inject them as a mixins. This approach could save a little bit of performance.

npm install vue-offline --save

And inside components that you want to have features listed below:

import VueOfflineMixin from 'vue-offline/mixin'

export default {
  mixins: [VueOfflineMixin]
}

Features

  • OnlineOnly data property available for each component - true only when online
  • OfflineOnly data property available for each component - true only when offline
  • online event - available in every component, emitted when user changes from offline to online
  • offline event - available in every component, emitted when user changes from online to offline

Example

<template>
  <div id="app">
    <div v-show="OnlineOnly">This part is visible only when user is online</div>
    <div v-show="OfflineOnly">This part is visible only if user is offline</div>
    <div> {{ onlineState }} </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      onlineState: navigator.onLine
    }
  },
  created () {
    this.$on('online', function () {
      this.onlineState = "I'm online now!" 
    })
    this.$on('offline', function () {
      this.onlineState = "I'm offline now!"
    })
  }
}
</script>

Keywords

FAQs

Package last updated on 06 Jun 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc