Skip to content

CodeCoupler Application Basics PWA Handling Vue 🔒

What is this?

This Vue component uses @codecoupler-pro/app-pwa to display an icon as soon as the browser detects a PWA and offers to install it. Depending on whether a desktop or mobile browser is detected, the appropriate icon is displayed.

Setup

Install Bundle:

npm i vue @codecoupler-pro/ui-bundle

Define Aliases, Externals and Assets:

{
  module: "@codecoupler-pro/app-pwa-vue",
  global: ["codecoupler", "app", "pwaVue"]
},
{
  module: "@codecoupler-pro/ui-bundle",
  global: ["codecoupler", "ui", "bundle"],
  entries: [
    "dist/codecoupler-pro-ui-bundle.js"
  ]
}

Basic Usage

Use it with JavaScript:

1
2
3
4
5
6
7
8
9
import { PWAVue } from "@codecoupler-pro/app-pwa-vue";
import { PWA } from "@codecoupler-pro/app-pwa";
import { createApp } from "vue";

let vueApp = createApp(PWAVue, {
  pwa: new PWA(),
  /* optional additional props */
});
vueApp.mount(element);

Use it as a CodeCoupler Costa Component:

import { PWAVue } from "@codecoupler-pro/app-pwa-vue";
import { PWA } from "@codecoupler-pro/app-pwa";

await this.getStage("stage-id").load({
  component: Vue,
  options: {
    vue: PWAVue,
    props: {
      pwa: new PWA(),
      /* optional additional props */
    }
  }
});

Use it as Vue component:

<template>
  <PWAVue :pwa="pwa"></PWAVue>
</template>
<script>
import { PWAVue } from "@codecoupler-pro/app-pwa-vue";
import { PWA } from "@codecoupler-pro/app-pwa";

export default {
  components: { PWAVue },
  data: function() {
    return {
      pwa: new PWA();
    }
  },
}
</script>

Icons

The following identifiers can be used in the following:

  • mobile
  • desktop

CSS Classes:

The icons will use the class icon and the identifier as classname.

Override default icons:

You can override the default icons using the property iconsComponent. Create a Vue file with multiple svg icons and tag them with v-if like shown below. Place them all in one span element. Define then one prop icon:

icons-component-custom.vue
<template>
  <span>
    <svg v-if="icon === '{identifier}'"><!-- svg data --></svg>
    <svg v-if="icon === '{identifier}'"><!-- svg data --></svg>
    <svg v-if="icon === '{identifier}'"><!-- svg data --></svg>
  </span>
</template>
<script setup>
defineProps({ icon: { type: String, default: "" } });
</script>

Import this file and use this as prop:

import iconsComponentCustom from "icons-component-custom.vue"
import { PWAVue } from "@codecoupler-pro/app-pwa-vue";
import { PWA } from "@codecoupler-pro/app-pwa";
import { createApp } from "vue";

let vueApp = createApp(PWAVue, {
  pwa: new PWA(),
  iconsComponent: iconsComponentCustom
});
vueApp.mount(element);

Reference

The following props can be passed:

pwa: Object

PWA module instance.

iconsComponent: Vue

Overrides the default icons. See above.

showIconMobile: boolean and showIconDesktop: boolean

Handling the installation prompt works only in chromium based browsers. To show the icons in other bowsers (without any additional functionality) you can set these props to true.

showIcons: Object

To show the icons regardless of the current status you can pass the identifier as properties and the value true to this object. Example: { identifier1: true }.