Giter Club home page Giter Club logo

vue-online's Introduction

vue-online

A reactive online/offline component for vue.js

Vue online preview

Installation

npm install vue-online --save-dev

Usage

That's a basic example of a component which would just show the offline message if the user has no connection:

<template>
  <div id="app">
    <OfflineIndicator></OfflineIndicator>
  </div>
</template>

<script>
import { OfflineIndicator } from 'vue-online'

export default {
  name: 'app',
  components: {
    OfflineIndicator
  }
}
</script>

Advanced usage (with the reactive online variable)

You can use ConnectionStatus.online anywhere in your app, it updates dynamically as the connection of the user changes.

<template>
  <div id="app">
    Connection: <span v-if="online">online</span><span v-if="!online">offline</span>
    <OfflineIndicator></OfflineIndicator>
  </div>
</template>

<script>
import { OfflineIndicator, VueOnline } from 'vue-online'

export default {
  name: 'app',
  computed: {
    online () {
      return VueOnline.isOnline
    }
  },
  components: {
    OfflineIndicator
  }
}
</script>

Custom offline message

To use a custom message, simply specify it on the component:

<OfflineIndicator message="Oh no, you're offline :("></OfflineIndicator>

Custom styling

To style the offline indicator just use the css selector div.offline-indicator:

div.offline-indicator {
  background: red;
  color: white;
}

vue-online's People

Contributors

sopamo avatar

Watchers

Mike Massari avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.