微信小程序webview 顶部title设置

webview端为vue项目

webview取的是vue页面的<title>标签中的内容

在配置router时设置name值,每当页面跳转,路由发生改变时,动态修改页面的title。可通过路由前置守卫来实现:

  {
    path: "/",
    redirect: "login",
  },
  {
    path: "/login",
    component: () => import("../pages/login.vue"),
    name: "登录",
  },
  {
    path: "/index",
    component: () => import("../pages/index.vue"),
    name: "首页",
  },
// // 跳转之前
router.beforeEach((to, from, next) => {
  document.title = to.name;
  next();
});

webview端为uniapp项目

在webview页面的onLoad里设置标题:

wx.setNavigationBarTitle({
  title: '当前页面'})

猜你喜欢

转载自blog.csdn.net/weixin_58328414/article/details/128845154