Giter Club home page Giter Club logo

vue-native-notification's Introduction

vue-native-notification

Vue.js plugin for native notifications

Install

npm install --save vue-native-notification

Usage

Add plugin

import Vue from 'vue'
import VueNativeNotification from 'vue-native-notification'

Vue.use(VueNativeNotification, {
  // Automatic permission request before
  // showing notification (default: true)
  requestOnNotify: true
})

Show notification

<template>
  <button type="button" @click="notify">Show notification</button>
</template>

<script>
export default {
  methods: {
    notify () {
      // https://developer.mozilla.org/en-US/docs/Web/API/Notification/Notification#Parameters
      this.$notification.show('Hello World', {
        body: 'This is an example!'
      }, {})
    }
  }
}
</script>

<style>
</style>

Manual permission request

You can manually request users permission with:

// Global
Vue.notification.requestPermission()
  .then(console.log) // Prints "granted", "denied" or "default"

// Component
this.$notification.requestPermission()
  .then(console.log)

Events

https://developer.mozilla.org/en-US/docs/Web/API/Notification

We now supports all notifications events

onerror

https://developer.mozilla.org/en-US/docs/Web/API/Notification/onerror

Is an empty function. Nothing will be executed

onclick

https://developer.mozilla.org/en-US/docs/Web/API/Notification/onclick

When notification is clicked, we set the focus on the context browser and close the notification

onclose

https://developer.mozilla.org/en-US/docs/Web/API/Notification/onclose

Is an empty function. Nothing will be executed

onshow

https://developer.mozilla.org/en-US/docs/Web/API/Notification/onshow

Is an empty function. Nothing will be executed

Usage

const notification = {
  title: 'Your title',
  options: {
    body: 'This is an example!'
  },
  events: {
    onerror: function () {
        console.log('Custom error event was called');
    },
    onclick: function () {
        console.log('Custom click event was called');
    },
    onclose: function () {
        console.log('Custom close event was called');
    },
    onshow: function () {
        console.log('Custom show event was called');
    }
  }
}
this.$notification.show(notification.title, notification.options, notification.events)

License

MIT

vue-native-notification's People

Contributors

dennisbruner avatar louismazel avatar tinou98 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.