uniapp微信小程序无法屏蔽右上角胶囊按钮(...)问题解决方案

从网上查了很多方法,基本都是靠在pages.json中对应页面添加"navigationBarRightButton": {"hide":true}

javascript 复制代码
{
  "navigationBarTitleText": "我的页面",
  "navigationStyle": "custom",
  "navigationBarBackgroundColor": "#0000FF",
  "navigationBarRightButton": {"hide":true}, // 隐藏右侧胶囊按钮
  "usingComponents": {}
}

但是该方法仅限模拟器中生效,在真机下还是在的,所以没法去除或者隐藏胶囊按钮。

综上所述,只能想办法避开它

参考:https://uniapp.dcloud.net.cn/api/ui/menuButton.html#getmenubuttonboundingclientrect

实现效果如下:

代码如下,主要是靠margin-right:

html 复制代码
<!-- 分享图标 -->
<view class="share-icon-box" @tap="handleShare" :style="{marginRight:(statusWidth + searchRight+'px')}">
	<text class="iconfont icon-ic_share1"></text>
</view>
javascript 复制代码
			// #ifdef MP
			const res = uni.getMenuButtonBoundingClientRect()
			const statusHeight = res.top //胶囊距离顶部
			const statusRight = res.right //胶囊右边界坐标
			const jnHeight = res.height //胶囊高度
			this.statusWidth= res.width
			this.searchTop=statusHeight
			this.searchHeight=jnHeight
			this.searchBoxHeight = this.searchTop*2 + jnHeight
			//搜索框宽度计算
			uni.getSystemInfo({
				success:info=>{
					this.searchRight=info.windowWidth-statusRight
				}
			})
			// #endif

哎~~不想写了,小白一名如所写有误望指正,也希望各位大佬有更好的方法发出来让小弟学习一下

相关推荐
WangHappy11 小时前
不写 Canvas 也能搞定!小程序图片导出的 WebView 通信方案
前端·微信小程序
小时前端16 小时前
微信小程序选不了本地文件?用 web-view + H5 一招搞定
前端·微信小程序·uni-app
Mr_li1 天前
给 Vue 开发者的 uni-app 快速指南
vue.js·uni-app
anyup1 天前
🔥2026最推荐的跨平台方案:H5/小程序/App/鸿蒙,一套代码搞定
前端·uni-app·harmonyos
icebreaker2 天前
Weapp-vite:原生模式之外,多一种 Vue SFC 选择
前端·vue.js·微信小程序
icebreaker2 天前
重走 Vue 长征路 Weapp-vite:编译链路与 Wevu 运行时原理拆解
前端·vue.js·微信小程序
Mintopia2 天前
Vue3 项目如何迁移到 uni-app x:从纯 Web 到多端应用的系统指南
uni-app
Mintopia2 天前
uni-app x 发展前景技术分析:跨端统一的新阶段?
uni-app
不爱说话郭德纲3 天前
告别漫长的HbuilderX云打包排队!uni-app x 安卓本地打包保姆级教程(附白屏、包体积过大排坑指南)
android·前端·uni-app
大米饭消灭者4 天前
Taro是怎么实现一码多端的【底层原理】
微信小程序·taro