关于uniapp页面上方自定义按钮的隐藏
1、第一步在pages.json文件写上页面的按钮(titleNView里)
{
"path": "pages/homepage/list",
"style": {
"navigationBarTitleText": "列表",
"app-plus": {
"bounce": "vertical",
"titleNView": {
"buttons": [{
"text": "新增",
"fontSrc": "/static/uni.ttf",
"fontSize": "13px",
"color": "#FFFFFF",
"float": "right"
}]
}
},
"enablePullDownRefresh": true,
"onReachBottomDistance": 100
}
},
2、第二步,在页面加载时根据前一个页面传过来的数据判断是否显示该按钮
onLoad(options) {//onLoad函数与data、methods同级
var webview = this.$mp.page.$getAppWebview();
this.activeIndex = options.activeIndex
if(this.activeIndex==1)//传过来的值为1时按钮宽度设为0,视为隐藏
webview.setTitleNViewButtonStyle(0, {
width:'0px'
});
}
注:按钮宽度设为0并非真正的隐藏,如果哪位大佬了解有其他方法,欢迎分享和讨论。