- 当前 Bug 的表现(可附上截图)
usingComponents 引入页面onLoad未执行
- 预期表现
onLoad: function(options) {
console.log(111112);
},
- 复现路径
/pages/landlord/myHouse/myHouse
- 提供一个最简复现 Demo
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.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.js
Page({ /** * 页面的初始数据 */ data: { PageCur: 'myHouse' , // height: app.globalData.height * 2 + 24, }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { }, /** * 页面方法 */ NavChange(e) { this .setData({ PageCur: e.currentTarget.dataset.cur }) }, onShareAppMessage() { return { title: '我的房屋' , // imageUrl: '/images/share.jpg', path: 'pages/landlord/myHouse/myHouse' } }, }) |
页面如下 当加载页面
myHouse
在myHouse 页面 onLoad方法却未执行 这个是为什么了 如何调用onload呢
你把你想要在组件加载时执行的代码放到attached里面就可以了
楼主 请问这个问题解决了吗
怎么解决的?
怎么解决的呢
怎么解决的?
没人解答吗
你好,麻烦提供能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)