5--微信小程序 之 tabbar

index

  <!--pages/demo/index.wxml-->
<c-banji wx:if="{{current == 0}}" id='banji'></c-banji>
<c-my wx:else id="myinfo"></c-my>

<tui-tabbar tabBar="{{tabBar2}}"  current="{{current}}" bind:click="tabbarSwitch"></tui-tabbar>

// pages/demo/index.js
//获取应用实例
const app = getApp()
Page({
  data: {
    current: 0,
    tabBar2: [{
        "pagePath": "/pages/index/index",
        "text": "班级",
        "iconPath": "/static/images/my_banji1.png",
        "selectedIconPath": "/static/images/my_banji.png"
      },
      {
        "pagePath": "/pages/my/my",
        "text": "我的",
        "iconPath": "/static/images/wode1.png",
        "selectedIconPath": "/static/images/wode.png",
      }
    ],

  },
  
  onLoad:function(){
    if(this.data.current == 0){
      let banji=this.selectComponent("#banji")
      banji.getinfo()
    }else{
      let myinfo = this.selectComponent("#myinfo")
      myinfo.getinfo()
    }
  },


  tabbarSwitch(e) {
    this.setData({
      current: e.detail.index
    })
  }
})
{
  "usingComponents": {
    "tui-tabbar":"/static/thorui/components/tui-tabbar/tui-tabbar",
    "c-banji":"/pages/teacher/banji",
    "c-my":"/pages/teacher/my"
  }
}

猜你喜欢

转载自blog.csdn.net/xu_ze_qin/article/details/106885871