0.2.0 • Published 5 years ago

vue-pwa-installer v0.2.0

Weekly downloads
189
License
MIT
Repository
github
Last release
5 years ago

Vue PWA Installer

Adds an $installer interface to Vue instances for installing Progressive Web Apps.

yarn add vue-pwa-installer

Setup

import Vue from "vue"
import VueInstaller from "vue-pwa-installer"

Vue.use(VueInstaller, { /* options */ })

Usage

<template>
  <div>
    <div v-if="$installer.canInstall">
      <button @click="$installer.prompt">
    </div>
    <p v-if="$installer.choice">
      User {{$installer.choice}} prompt.
    </p>
    <p v-if="$installer.hasInstalled">
      App installed successfully.
    </p>
  </div>
</template>

Interface

KeyTypeDescription
promptFunctionPrompt the user to install the PWA when available.
choiceString?User choice following prompt dialog. Either null, "accepted" or "dismissed".
canInstallBooleanCan the app be installed via prompt.
hasInstalledBooleanHas the app been installed.

NOTE: Support for the underlying API is limited.

Options

KeyTypeDefaultDescription
prototypeKeyString$installerVue prototype key to add the installer instance to.
storageKeyStringhasInstalledPWALocalStorage key to store installed state of the PWA.

Nuxt

To inject a PWA installer into a Nuxt application:

// plugins/installer.js
import Vue from "vue"
import { createInstaller } from "vue-pwa-installer"

export default (context, inject) => {
  const installer = createInstaller(Vue, { /* options */ })
  inject("$installer", installer)
}

The $installer interface will now be available in Vue components, Nuxt's app instance and the Vuex store.

Author

Matthew Wagerfield

License

MIT