usingComponents 引入页面onLoad未执行
发布于 6 年前 作者 ezhong 5335 次浏览 来自 问答
  • 当前 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

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
    })
  },
  onShareAppMessage() {
    return {
      title: '我的房屋',
      // imageUrl: '/images/share.jpg',
      path: 'pages/landlord/myHouse/myHouse'
    }
  },
 
 
 
})

页面如下 当加载页面

myHouse

myHouse 页面 onLoad方法却未执行 这个是为什么了 如何调用onload呢

3 回复

怎么解决的?

没人解答吗

回到顶部