usingComponents 引入页面onLoad未执行
- 当前 Bug 的表现(可附上截图)
usingComponents 引入页面onLoad未执行
- 预期表现
onLoad: function(options) {
console.log(111112);
},
- 复现路径
/pages/landlord/myHouse/myHouse
- 提供一个最简复现 Demo
在myHouse 页面 onLoad方法却未执行 这个是为什么了 如何调用onload呢
分享代码如下:
https://developers.weixin.qq.com/s/rfch5Smr7Y9I
/** * 生命周期函数--监听页面加载 */ onLoad: function (options) { console.log(111112); }, |
onLoad 方法未执行
index.json 引入对应的页面
{ "usingComponents" : { "myHouse" : "/pages/landlord/myHouse/myHouse" , "contract" : "/pages/landlord/contract/contract" , "houseControl" : "/pages/landlord/houseControl/houseControl" , "rent" : "/pages/landlord/rent/rent" , "personal" : "/pages/landlord/personal/personal" } } |
index.wxml
<myHouse wx: if = "{{PageCur == 'myHouse'}}" ></myHouse> <contract wx: if = "{{PageCur == 'contract'}}" ></contract> <houseControl wx: if = "{{PageCur == 'houseControl'}}" ></houseControl> <rent wx: if = "{{PageCur == 'rent'}}" ></rent> <personal wx: if = "{{PageCur == 'personal'}}" ></personal> <view class= "cu-bar tabbar shadow foot" > <view class= "action" bindtap= "NavChange" data-cur= "myHouse" > <view class= 'cuIcon-cu-image' > <image src= "/images/icon/myHouse{{PageCur=='myHouse'?'_cur':''}}.png" ></image> </view> <view class= " {{PageCur=='myHouse'?'text-green':'text-bar'}}" >我的房屋</view> </view> <view class= "action" bindtap= "NavChange" data-cur= "contract" > <view class= 'cuIcon-cu-image' > <image src= "/images/icon/contract{{PageCur=='contract'?'_cur':''}}.png" ></image> </view> <view class= "{{PageCur=='contract'?'text-green':'text-bar'}}" >合同管理</view> </view> <view class= "action" bindtap= "NavChange" data-cur= "houseControl" > <view class= 'cuIcon-cu-image' > <image src= "/images/icon/houseControl{{PageCur=='houseControl'?'_cur':''}}.png" ></image> </view> <view class= "{{PageCur=='houseControl'?'text-green':'text-bar'}}" >房控</view> </view> <view class= "action" bindtap= "NavChange" data-cur= "rent" > <view class= 'cuIcon-cu-image' > <image src= "/images/icon/rent{{PageCur=='rent'?'_cur':''}}.png" ></image> </view> <view class= "{{PageCur=='rent'?'text-green':'text-bar'}}" >收租</view> </view> <view class= "action" bindtap= "NavChange" data-cur= "personal" > <view class= 'cuIcon-cu-image' > <image src= "/images/icon/personal{{PageCur=='personal'?'_cur':''}}.png" ></image> </view> <view class= "{{PageCur=='personal'?'text-green':'text-bar'}}" >个人中心</view> </view> </view> |
index.js
const app = getApp(); Page({ /** * 页面的初始数据 */ data: { PageCur: 'myHouse' , // height: app.globalData.height * 2 + 24, }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { }, /** * 页面方法 */ NavChange(e) { this .setData({ PageCur: e.currentTarget.dataset.cur }) let page = getCurrentPages().pop(); if (page == undefined || page == null ) { return ; } page.onLoad(); }, onShareAppMessage() { return { title: '我的房屋' , // imageUrl: '/images/share.jpg', path: 'pages/landlord/myHouse/myHouse' } }, }) |
usingComponents 引入的页面 onLoad 方法未执行
这个要如何处理呢?
求大神帮帮忙 给与解答 谢谢