alanhe421 / coding-note

note
3 stars 1 forks source link

pwa一些问题总结 #453

Open alanhe421 opened 1 year ago

alanhe421 commented 1 year ago

PWA 应用本质是桌面快捷方式

配置项说明

display

minimal-ui image

standalone image

name/short_name/display配置修改更新

比如name修改,再浏览器重启访问网站是会提示更新,但比如display配置修改,重启浏览器访问app,不会提示,直接会使用最新的。

theme_color

控制title bar部分 image

动态修改theme_color,可以通过动态修改<meta name="theme-color" content="#0066ff"/>来解决

调试

alanhe421 commented 1 year ago

image

icon尺寸

alanhe421 commented 1 year ago

自定义安装按钮唤起PWA安装

image

 let deferredPrompt;
  const installApp = document.getElementById('installApp');

  window.addEventListener('beforeinstallprompt', (e) => {
    installApp.style.display = 'block';
    deferredPrompt = e;
  });

  installApp.addEventListener('click', async () => {
    if (deferredPrompt !== null) {
      deferredPrompt.prompt();
      const {outcome} = await deferredPrompt.userChoice;
      if (outcome === 'accepted') {
        deferredPrompt = null;
      }
    }
  });
alanhe421 commented 1 year ago

pwa兼容性

image

alanhe421 commented 1 year ago

相关文章