feat: add install pwa button
This commit is contained in:
6
app.vue
6
app.vue
@@ -1,5 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
// import { installPrompt } from './utils/pwa'
|
import { installPrompt } from './utils/pwa'
|
||||||
import { appName } from '~/constants'
|
import { appName } from '~/constants'
|
||||||
|
|
||||||
// https://github.com/vueuse/head
|
// https://github.com/vueuse/head
|
||||||
@@ -15,7 +15,9 @@ useHead({
|
|||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|
||||||
// installPrompt()
|
onMounted(() => {
|
||||||
|
installPrompt()
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|||||||
@@ -20,8 +20,14 @@ function install() {
|
|||||||
<template>
|
<template>
|
||||||
<Transition>
|
<Transition>
|
||||||
<div v-if="app.deferredPrompt" text="center" m="t-2">
|
<div v-if="app.deferredPrompt" text="center" m="t-2">
|
||||||
<button class="shadow" text="white" bg="green-500" p="x-4 y-0" m="2" @click="install">
|
<button
|
||||||
安装
|
class="shadow"
|
||||||
|
text="white" bg="green-500" p="x-4 y-2" m="2" inline-flex
|
||||||
|
items-center justify-center rounded-md font-bold
|
||||||
|
@click="install"
|
||||||
|
>
|
||||||
|
<div i-ri-install-line mr-1 inline-flex />
|
||||||
|
<span inline-flex>安装到桌面</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</Transition>
|
</Transition>
|
||||||
|
|||||||
@@ -3,6 +3,9 @@
|
|||||||
<h1 text-2xl font="bold" my="4">
|
<h1 text-2xl font="bold" my="4">
|
||||||
帮助
|
帮助
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
|
<InstallPwa />
|
||||||
|
|
||||||
<FeedbackActions />
|
<FeedbackActions />
|
||||||
|
|
||||||
<div class="mx-auto max-w-md w-full rounded-2xl bg-white p-2" text-left>
|
<div class="mx-auto max-w-md w-full rounded-2xl bg-white p-2" text-left>
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import { isClient } from '@vueuse/core'
|
import { isClient } from '@vueuse/core'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* https://web.dev/customize-install/#detect-install
|
* - https://web.dev/customize-install/#detect-install
|
||||||
|
* - [Trigger installation from your PWA](https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps/How_to/Trigger_install_prompt)
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export function installPrompt() {
|
export function installPrompt() {
|
||||||
@@ -12,9 +13,10 @@ export function installPrompt() {
|
|||||||
|
|
||||||
window.addEventListener('beforeinstallprompt', (e) => {
|
window.addEventListener('beforeinstallprompt', (e) => {
|
||||||
// Prevent the mini-infobar from appearing on mobile
|
// Prevent the mini-infobar from appearing on mobile
|
||||||
// e.preventDefault()
|
e.preventDefault()
|
||||||
// Stash the event so it can be triggered later.
|
// Stash the event so it can be triggered later.
|
||||||
app.deferredPrompt = e
|
app.deferredPrompt = e
|
||||||
|
|
||||||
// Update UI notify the user they can install the PWA
|
// Update UI notify the user they can install the PWA
|
||||||
// showInstallPromotion()
|
// showInstallPromotion()
|
||||||
// Optionally, send analytics event that PWA install promo was shown.
|
// Optionally, send analytics event that PWA install promo was shown.
|
||||||
|
|||||||
Reference in New Issue
Block a user