b***@qq.com
b***@qq.com
  • 发布:2020-06-12 18:04
  • 更新:2020-06-12 18:04
  • 阅读:530

【报Bug】页面在加入tabBar的情况下,设置导航栏按钮报错

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: win7

HBuilderX类型: 正式

HBuilderX版本号: 2.7.9

手机系统: Android

手机系统版本号: Android 7.1.1

手机厂商: vivo

手机机型: vivo

页面类型: vue

打包方式: 云端

项目创建方式: HBuilderX

示例代码:

let pages = getCurrentPages();
let page = pages[pages.length - 1];
if (text.length > 3) {
text = text.substr(0, 3) + '...';
}
// #ifdef APP-PLUS
let currentWebview = page.$getAppWebview();
console.log(currentWebview)
let titleNView = currentWebview.getStyle().titleNView;
// 添加文字过长截取为3个字符,请根据自己业务需求更改
titleNView.buttons[0].text = text;
currentWebview.setStyle({
titleNView: titleNView
});
// #endif

操作步骤:

配置:

"tabBar": {  
        "color": "#7A7E83",  
        "selectedColor": "#3598DC",  
        "borderStyle": "black",  
        "backgroundColor": "#F8F8F8",  
        "list": [{  
                "pagePath": "pages/index/index",  
                "text": "首页"  
            },  
            {  
                "pagePath": "pages/test/test",  
                "text": "买车"  
            }  
        ]  
    }

页面

setNavCity(text) {  
                //let text = this.cityName;  
                let pages = getCurrentPages();  
                let page = pages[pages.length - 1];  
                if (text.length > 3) {  
                    text = text.substr(0, 3) + '...';  
                }  
                // #ifdef APP-PLUS  
                let currentWebview = page.$getAppWebview();  
                let titleNView = currentWebview.getStyle().titleNView;  
                // 添加文字过长截取为3个字符,请根据自己业务需求更改  
                titleNView.buttons[0].text = text;  
                currentWebview.setStyle({  
                    titleNView: titleNView  
                });  
                // #endif  
                // #ifdef H5  
                // h5 临时方案  
                document.getElementsByClassName('uni-btn-icon')[1].innerText = text;  
                // #endif  
            }

预期结果:

导航栏按钮文字应该是 setNavCity 设置的内容

实际结果:

模拟器/真机调试结果: TypeError: undefined is not an object (evaluating 'titleNView.buttons')

bug描述:

页面加入tabBar的情况下,设置导航栏按钮报错,TypeError: undefined is not an object (evaluating 'titleNView.buttons')

let pages = getCurrentPages();  
                let page = pages[pages.length - 1];  
                if (text.length > 3) {  
                    text = text.substr(0, 3) + '...';  
                }  
                // #ifdef APP-PLUS  
                let currentWebview = page.$getAppWebview();  
                console.log(currentWebview)  
                let titleNView = currentWebview.getStyle().titleNView;  
                // 添加文字过长截取为3个字符,请根据自己业务需求更改  
                titleNView.buttons[0].text = text;  
                currentWebview.setStyle({  
                    titleNView: titleNView  
                });

不在tabBar的页面,可以正常使用该功能

但我们的实际应用,基本上都是在首页,会在导航栏显示城市,而首页也是在tabBar里面,所以这个问题把我们卡住了

2020-06-12 18:04 负责人:无 分享
已邀请:

该问题目前已经被锁定, 无法添加新回复