小程序 webview 标题设置

发布时间 2023-12-11 08:56:31作者: 212的s

//小程序 uni.setNavigationBarTitle设置后,会被webview页面的标题覆盖,后面再设置也不会刷新
//在h5页面中设置,也会被vue的默认标题覆盖掉,并且之后无法刷新小程序显示的标题
//只能在h5那边,vue页面router权限处理的地方(/router/permissions.ts中 router.afterEach 处),第一次给document.title赋值的时候处理

 

 

例如:

请求地址为   https://xxxx.com/#/papers/xx?a=x&b=x&title=标题

 

可以这样

 router.afterEach((to: any) => {
  if (to.path == '/papers/xx' && location.hash){
    var t = location.hash.split('&').pop().split('=').pop()    
    document.title = decodeURI(t)
  }