router.js设置标题名称
//引入组件 export default [ //Home路由 { path:'/', // component:Home component: () => import('@/views/Home/index'), }, //服务商详情 { path:'/ServiceDetail', // component:ServiceDetail component: () => import('@/views/ServiceDetail/index'), meta: { title:'服务商详情' } }, //服务产品详情 **************** { path:'/Serviceproduct', // component:ServiceDetail component: () => import('@/views/Serviceproduct/index'), meta: { title:'服务产品详情' } }, //路由的重定向 { path:'/', redirect: '/' } ]
复制成功
router.beforeEach((to, from, next) => { if (to.meta.title) { document.title = to.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) } var iframe = document.createElement('iframe'); iframe.style.visibility = 'hidden'; iframe.style.width = '1px'; iframe.style.height = '1px'; iframe.onload = function () { setTimeout(function () { document.body.removeChild(iframe); }, 0); }; document.body.appendChild(iframe); 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) } } next() })
复制成功