uniapp添加導航欄按鈕及監聽事件


{
"path":"pages/log/log",
"style": {
    "navigationBarTitleText":"hello",
    "app-plus": {
        "titleNView": {
             "buttons": [{
                "text":"","fontSize":"22px",
          "width":"50px" }]              }          }      }  }

頁面監聽

 onNavigationBarButtonTap() {
 
           console.log("點擊了自定義按鈕");     
 
}
// #ifdef APP-PLUS  
var webView = this.$mp.page.$getAppWebview();  
 
// 修改buttons  
// index: 按鈕索引, style {WebviewTitleNViewButtonStyles }  
webView.setTitleNViewButtonStyle(0, {  
    text: 'hello',  
});  
 
// 修改按鈕上的角標  
// index: 按鈕索引, text: 角標文本內容  
webView.setTitleNViewButtonBadge({  
    index: 0,  
    text: 10,  
});  
 
// 設置 searchInput的 focus  
// focus: true | false  
webView.setTitleNViewSearchInputFocus(true)  
 
// 設置 searchInput的 text  
webView.setTitleNViewSearchInputText(text)  
 
// searchInput 通過 webview 的 setStyle 方法進行更新  
var tn = currentWebview.getStyle().titleNView;  
if (tn.buttons) {    
uni.getSystemInfo({    
    success:function(res){    
        if (res.platform=="ios") { // 這里在HBuilderX 1.9.9版本有個bug,searchInput的I變小寫了 ,臨時繞過下。更高版本會修復此bug    
            tn.searchinput.placeholder = 'test';    
            currentWebview.setStyle({    
                titleNView: tn    
            });    
        } else{    
            tn.searchInput.placeholder = 'test'; //這里有個已知bug,HBuilderX 1.9.9上,當searchInput位於首頁時,動態設置placehold會導致buttons的點擊事件消失。更高版本會修復此bug    
            currentWebview.setStyle({    
                titleNView: tn    
            });    
        }    
    }    
})    
}    
 
// #endif  
// 修改導航欄信息
onReady() { let buttons
= '按鈕' //buttons = '\ue670' 如果是字體圖標需要引入ttf文件 // #ifdef APP-PLUS var currentWebview = this.$mp.page.$getAppWebview(); console.log(currentWebview) var tn = currentWebview.getStyle().titleNView; tn.buttons[0].text = buttons; //[0] 按鈕的下標 currentWebview.setStyle({ titleNView: tn }); // #endif }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM