一、问题描述

有个需求就是,在app.vue页面中首先会隐藏所有页面的title,然后在相应的页面会判断当前环境是否是在微信浏览器内,如果不是,则还原标题。

二、解决方法

在 pages.json 文件中设置 navigationBarTitleText,例如:

{
	"pages": [
    {
      "path": "pages/xxx/index",
      "style": {
        "navigationBarTitleText": "首页",
        "app-plus": {
          "bounce": "none"
        }
      }
    }]
}

在页面中,使用以下代码获取当前页面的 navigationBarTitleText 的值:

<template>
	<view>1111</view>
</template>
<script>
export default {
  data() {
    return {
      title: "",
    };
  },
  mounted() {
    const pages = getCurrentPages();
    const currentPage = pages[pages.length - 1];
    // #ifndef APP-PLUS
    this.title = currentPage.$page.meta.navigationBar.titleText;
    // #endif

    // #ifdef APP-PLUS
    let webView = currentPage.$getAppWebview();
    this.title = webView.getStyle().name;
    // #endif
  },
};
</script>

如果获取不到,可按如下方式,去跟踪,然后替换下面的代码

currentPage.$page.meta.navigationBar.titleText;

GitHub 加速计划 / js / json
58
5
下载
适用于现代 C++ 的 JSON。
最近提交(Master分支:1 个月前 )
b451735f Bumps [lukka/get-cmake](https://github.com/lukka/get-cmake) from 4.0.2 to 4.0.3. - [Release notes](https://github.com/lukka/get-cmake/releases) - [Commits](https://github.com/lukka/get-cmake/compare/ea004816823209b8d1211e47b216185caee12cc5...6b3e96a9bc9976b8b546346fdd102effedae0ca8) --- updated-dependencies: - dependency-name: lukka/get-cmake dependency-version: 4.0.3 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> 4 天前
568b708f Bumps [step-security/harden-runner](https://github.com/step-security/harden-runner) from 2.12.0 to 2.12.1. - [Release notes](https://github.com/step-security/harden-runner/releases) - [Commits](https://github.com/step-security/harden-runner/compare/0634a2670c59f64b4a01f0f96f84700a4088b9f0...002fdce3c6a235733a90a27c80493a3241e56863) --- updated-dependencies: - dependency-name: step-security/harden-runner dependency-version: 2.12.1 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> 9 天前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐