uniapp隐藏胶囊体
时间: 2025-02-09 08:21:35 浏览: 65
### 如何在 UniApp 中隐藏胶囊按钮
#### 页面配置方式
通过修改页面配置文件中的 `navigationBarRightButton` 属性来隐藏右上角的默认胶囊按钮[^2]。
```json
{
"navigationBarRightButton": {
"hide": true
}
}
```
此方法适用于不需要动态控制胶囊按钮显示的情况,在项目构建时静态生效。
#### 动态隐藏胶囊按钮
对于需要根据条件动态隐藏胶囊按钮的情形,可以在页面加载函数 `onLoad()` 方法内调用微信JS-SDK接口完成操作。具体实现如下所示:
```javascript
export default {
onLoad() {
const that = this;
let url = `${that.$http.baseUrl2}${window.location.pathname}`;
console.log("当前页面完整路径:", url);
that.$http.get('api/user/signature', { url }).then((res) => {
console.log("隐藏验证:", res);
if (res.status_code === 200) {
wx.config({
debug: false,
appId: res.data.appId,
timestamp: res.data.timestamp,
nonceStr: res.data.nonceStr,
signature: res.data.signature,
jsApiList: ['hideOptionMenu']
});
wx.ready(() => {
wx.hideOptionMenu();
});
wx.error((err) => {
console.error(err);
});
} else {
that.$tool.toast(res.message);
}
});
},
};
```
上述代码片段展示了如何利用微信 JS SDK 的 `config` 和 `ready` 函数配合使用以达到隐藏效果,并处理可能发生的错误情况[^3]。
阅读全文
相关推荐


















