在ios下app 設置document.title = "titleName" 失效,原因是在IOS webview中網頁標題只加載一次,動態改變是無效的。
在路由配置中添加 meta對象 如:
在路由配置js里面添以下代碼
router.afterEach(route => { // 從路由的元信息中獲取 title 屬性 if (route.meta.title) { document.title = route.meta.title; // 如果是 iOS 設備,則使用如下 hack 的寫法實現頁面標題的更新 if (navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)) { const hackIframe = document.createElement('iframe'); hackIframe.style.display = 'none'; hackIframe.src = '/static/html/fixIosTitle.html?r=' + Math.random(); document.body.appendChild(hackIframe); setTimeout(_ => { document.body.removeChild(hackIframe) }, 300) } } });
在static下添加一個空頁面
完美解決問題;
摘抄自 :https://segmentfault.com/a/1190000008853962