uniapp 智能显示导航栏 微信QQ浏览器下隐藏 H5下显示 解决微信双标题问题

uniapp h5 手机版在微信里会显示双标题的问题,如下图。

效果非常不好,为了实现完美的显示效果,只需要在main.js里加入以下代码即可。

实现在微信、QQ浏览器下自动隐藏导航栏解决双标题问题,在H5手机浏览器下显示导航。


Vue.mixin({
    mounted() {
        if (this.isWeiXinBrowser() || this.isQQBrowser()) {
            this.navTitle()
        }
    },
    methods: {
        isWeiXinBrowser() {
            let ua = navigator.userAgent.toLowerCase()
            return ua.indexOf('micromessenger') != -1
        },
        isQQBrowser() {
            var ua = navigator.userAgent.toLowerCase()
            if (ua.match(/QQ/i) == "qq") {
                return true
            } else {
                return false
            }
        },
        navTitle() {
            this.$nextTick(() => {
                let navTitleDom = document.getElementsByTagName('uni-page-head')
                if (navTitleDom.length) {
                    navTitleDom[0].style.display = 'none'
                }
            })
        }
    }
})

加入代码的效果图,如下:

方法二:在文件里修改

mounted() {
	var title = document.getElementsByClassName("uni-page-head__title")[0]
	title.textContent = "我的列表"
},

  • 6
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
要实现自定义导航栏微信胶囊按钮对齐,可以按照以下步骤进行: 1. 首先在 `App.vue` 中设置导航栏的高度为微信胶囊按钮的高度,即44px。可以使用 `uni.getSystemInfoSync()` 获取系统信息,再根据 `statusBarHeight` 和 `menuButtonBoundingClientRect.height` 计算出导航栏的高度。 ``` <template> <view class="navigation-bar" :style="{ height: navigationBarHeight + 'px' }"> <!-- 自定义导航栏内容 --> </view> </template> <script> export default { data() { return { navigationBarHeight: 0 } }, mounted() { const systemInfo = uni.getSystemInfoSync() const { statusBarHeight, menuButtonBoundingClientRect } = systemInfo this.navigationBarHeight = statusBarHeight + menuButtonBoundingClientRect.height } } </script> <style> .navigation-bar { position: fixed; top: 0; left: 0; right: 0; background-color: #fff; z-index: 999; } </style> ``` 2. 接下来,在页面中使用 `uni.getMenuButtonBoundingClientRect()` 获取微信胶囊按钮的位置信息,然后根据位置信息计算出导航栏左侧和右侧的边距。 ``` <template> <view class="navigation-bar" :style="{ height: navigationBarHeight + 'px', paddingLeft: paddingLeft + 'px', paddingRight: paddingRight + 'px' }"> <!-- 自定义导航栏内容 --> </view> </template> <script> export default { data() { return { navigationBarHeight: 0, paddingLeft: 0, paddingRight: 0 } }, mounted() { const systemInfo = uni.getSystemInfoSync() const { statusBarHeight, menuButtonBoundingClientRect } = systemInfo this.navigationBarHeight = statusBarHeight + menuButtonBoundingClientRect.height const { left, right } = uni.getMenuButtonBoundingClientRect() this.paddingLeft = left this.paddingRight = systemInfo.windowWidth - right } } </script> <style> .navigation-bar { position: fixed; top: 0; left: 0; right: 0; background-color: #fff; z-index: 999; } </style> ``` 通过以上步骤,就可以实现自定义导航栏微信胶囊按钮对齐了。需要注意的是,如果页面中使用了 `uni.setNavigationBarTitle()` 等原生导航栏相关方法,需要自行计算出对应的边距。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值