【发布时间】:2020-07-20 12:39:33
【问题描述】:
我已经使用 vue cli 标准安装了 PWA 应用。 之后,我只需添加此guide 提供的代码。
但是当我访问 http://localhost:8080/ 时,什么都没有触发。
这是 App.vue 代码:
<template>
<div id="app">
<img alt="Vue logo" src="./assets/logo.png">
<HelloWorld msg="PWA Test"/>
</div>
</template>
<script>
import HelloWorld from './components/HelloWorld.vue'
let deferredPrompt;
function showInstallPromotion() {
alert("ciao");
console.log(deferredPrompt);
}
export default {
name: 'App',
components: {
HelloWorld
},
created() {
window.addEventListener('beforeinstallprompt', (e) => {
alert("beforeinstallprompt");
// Prevent the mini-infobar from appearing on mobile
e.preventDefault();
// Stash the event so it can be triggered later.
deferredPrompt = e;
// Update UI notify the user they can install the PWA
showInstallPromotion();
});
},
mounted() {
if("serviceWorker" in navigator) {
navigator.serviceWorker.register("service-worker.js").then(reg => {
console.log("Registration succesful, scope: " + reg.scope);
})
.catch(err => {
console.log(err);
})
}
}
}
</script>
<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>
明显的问题?我相信使用 vue cli 会受到尊重。如何检查清单是否正常以及是否已准备好使用 PWA 应用程序? 在这个世界上的第一步,我错在哪里?谢谢
这是我的 manifest.json(在公用文件夹中):
{
"name": "vuejspwa",
"short_name": "vuejspwa",
"icons": [
{
"src": "./img/icons/android-chrome-192x192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "./img/icons/android-chrome-512x512.png",
"sizes": "512x512",
"type": "image/png"
}
],
"start_url": "./index.html",
"display": "fullscreen",
"background_color": "#000000",
"theme_color": "#4DBA87"
}
【问题讨论】:
标签: vue.js progressive-web-apps