Component({
/**
* 組件的屬性列表
*/
properties: {
receiveData: {
type: null,
observer: function (newVal, oldVal) {
console.log("頂部狀態欄參數:");
console.log(newVal);
this.setData({
isshowbtn: newVal.isshowbtn,//是否顯示按鈕
isshowpre: newVal.isshowpre, //返回按鈕
isshowhome:newVal.isshowhome, //首頁按鈕
title: newVal.title, //標題
})
}
},
},
/**
* 組件的初始數據
*/
data: {
statusBarHeight: getApp().globalData.statusBarHeight
},
/**
* 組件的方法列表
*/
methods: {
//點擊返回前一個頁面
goprepageopt: function() {
console.log("點擊返回上個頁面");
this.triggerEvent('prechange', 'false');
},
//點擊返回首頁頁面
gohomepageopt: function() {
console.log("點擊返回首頁");
this.triggerEvent('homechange', 'false');
},
}
})
{
"navigationStyle":"custom",
"navigationBarTitleText": "標題",
"usingComponents": {
"statusbars":"../../components/statubars/index"
}
}
《2》index.wxml
<statusbars receiveData="{{statusbarobj}}" bindprechange="prechangeopt" bindhomechange="homechangeopt" />
《3》index.js初始化組件數據和組件點擊事件的回調
/**
* 生命週期函數--監聽頁面顯示
*/
onShow: function () {
var that=this;
that.setData({
statusbarobj:{
isshowbtn: true,//是否顯示按鈕
isshowpre: true, //返回按鈕
isshowhome: true, //首頁按鈕
title:"標題標題標題標題標題標題標題標題標題標題標題標題", //標題
}
})
},
prechangeopt:function(){
console.log("組件回調,返回上一頁");
},
homechangeopt:function(){
console.log("組件回調,返回首頁");
},
7>測試頁面效果
《1》所有顯示
《2》只顯示首頁iconxss

《3》只顯示返回按鈕函數

《4》只顯示標題測試
