pwa: automatyczny reload

This commit is contained in:
2023-01-03 01:29:15 +01:00
parent 6a10b1e191
commit 242be73c78
4 changed files with 19 additions and 6 deletions
+1 -1
View File
@@ -5,7 +5,7 @@
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"build": "vue-tsc --noEmit && vite build", "build": "vue-tsc --noEmit && vite build",
"preview": "vite preview" "preview": "yarn build && vite preview --port 4174"
}, },
"dependencies": { "dependencies": {
"pinia": "^2.0.17", "pinia": "^2.0.17",
+3 -1
View File
@@ -69,7 +69,9 @@ export default defineComponent({
}), }),
async created() { async created() {
const stockData = await (await fetch(`https://spythere.github.io/api/stockDataNew.json?t=${Math.floor(Date.now() / 60000)}`)).json(); const stockData = await (
await fetch(`https://spythere.github.io/api/stockDataNew.json?t=${Math.floor(Date.now() / 60000)}`)
).json();
this.store.stockData = stockData; this.store.stockData = stockData;
}, },
+11 -3
View File
@@ -1,10 +1,18 @@
import { createApp } from 'vue'; import { createApp } from 'vue';
import { createPinia } from 'pinia'; import { createPinia } from 'pinia';
import { registerSW } from 'virtual:pwa-register';
import App from './App.vue'; import App from './App.vue';
const pinia = createPinia(); const pinia = createPinia();
createApp(App) const updateSW = registerSW({
.use(pinia) onOfflineReady() {},
.mount('#app');
onNeedRefresh() {
console.log('Need refresh!');
},
});
createApp(App).use(pinia).mount('#app');
+4 -1
View File
@@ -11,7 +11,10 @@
"isolatedModules": true, "isolatedModules": true,
"esModuleInterop": true, "esModuleInterop": true,
"lib": ["ESNext", "DOM"], "lib": ["ESNext", "DOM"],
"skipLibCheck": true "skipLibCheck": true,
"types": [
"vite-plugin-pwa/client"
]
}, },
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"], "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
"references": [{ "path": "./tsconfig.node.json" }] "references": [{ "path": "./tsconfig.node.json" }]