uniApp 隐藏头部右侧按钮 2.0
·
因为有业务需求动态隐藏 所以特此写了App和H5情况的显示隐藏 复制即可用
// #ifdef APP
let webView = that.$mp.page.$getAppWebview();
webView.setTitleNViewButtonStyle(0,{
width: '0'
});
// #endif
// #ifdef H5
document.querySelector('.uni-page-head .uni-page-head-ft .uni-page-head-btn').setAttribute("style","display:none")
// #endif
// #ifdef H5
this.$nextTick(() => {
// 使用 nextTick 确保 DOM 存在
const btn = document.querySelector('.uni-page-head .uni-page-head-ft .uni-page-head-btn');
if (btn) {
btn.style.display = this.sysType == 1 ? 'block' : 'none';
console.log(btn,'btn');
} else {
setTimeout(() => {
const retryBtn = document.querySelector('.uni-page-head .uni-page-head-ft .uni-page-head-btn');
console.log(retryBtn, 'retryBtn');
if (retryBtn) retryBtn.style.display = this.sysType == 1 ? 'block' : 'none';
}, 50);
}
});
// #endif
// #ifdef H5
this.$nextTick(() => {
document.querySelector('.uni-page-head .uni-page-head-ft .uni-page-head-btn').setAttribute("style", "display: " + (this.sysType == 1 ? 'block' : 'none'))
});
// #endif
更多推荐

所有评论(0)