收藏
回答

自定义tabbar,不同角色进来显示不一样的tabbar,上一个角色登录,缓存还在。怎么解决?

const app = getApp();

Component({

data: {

selected:

"custom": true

"color": "#472E0B"

"selectedColor": "#472E0B"

"borderStyle": "black"

"backgroundColor": "#ccc"

// 菜单1

"list": [

],

"list1": [

{

"pagePath": "/pages/orderList/orderList"

"text": "订单"

"iconPath": "../images/dingdanhui.png"

"selectedIconPath": "../images/dingdanlan.png"

},

{

"pagePath": "/pages/mine/mine"

"text": "我的"

"iconPath": "../images/minhui.png"

"selectedIconPath": "../images/minelan.png"

}

],

//菜单2

"list2": [

{

"pagePath": "/pages/agent_equipment/agent_equipment"

"text": "设备"

"iconPath": "../images/shebei1.png"

"selectedIconPath": "../images/shebei.png"

},

{

"pagePath": "/pages/agent_me/agent_me"

"text": "我的"

"iconPath": "../images/me.png"

"selectedIconPath": "../images/me1.png"

}

],

"position": "bottom"

},

// -- 初始化判断角色

attached() {

this.setData({

list: []

})

if ( 100 == app.globalData.type){

this.setData({

list: this.data.list2

})

}else

this.setData({

list: this.data.list1

})

}


},

methods: {

switchTab(e) {

const data = e.currentTarget.dataset;

const url = data.path;

wx.switchTab({

url: url

})

this.setData({

selected: data.index

})

}

}

})




<!-- wxm l-->

cover-viewclass"tab-bar">

cover-viewclass"tab-bar-border"></cover-view

cover-viewwx:for"{{list}}"wx:key"index"class"tab-bar-item"data-path"{{item.pagePath}}"data-index"{{index}}"bindtap"switchTab">

cover-imagesrc"{{selected === index ? item.selectedIconPath : item.iconPath}}"></cover-image

cover-viewstyle"color: {{selected === index ? selectedColor : color}}">{{item.text}}</cover-view

</cover-view

</cover-view



回答关注问题邀请回答
收藏

3 个回答

  • 罗梅光
    罗梅光
    2019-12-28

    不同角色进到小程序需要登录吧,重写缓存或全局变量。

    2019-12-28
    赞同 1
    回复 1
    • loysen罗
      loysen罗
      2019-12-30
      试过了,没用的
      2019-12-30
      回复
  • 晋威
    晋威
    2019-12-31

    app.globalData.type变化了吗?

    2019-12-31
    赞同
    回复 2
    • loysen罗
      loysen罗
      2019-12-31
      变化了,但是page页面的没有发生变化,猜测和生命周期有关
      2019-12-31
      回复
    • 晋威
      晋威
      2019-12-31回复loysen罗
      我试了是正常的,最好提供一个代码片段吧
      2019-12-31
      回复
  • loysen罗
    loysen罗
    2019-12-27

    wx.switchTab({

    'url': '/pages/agent_equipment/agent_equipment'

    })


    2019-12-27
    赞同
    回复
登录 后发表内容
问题标签