1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- // custom-tab-bar/index.js
- Component({
- data: {
- rightId:wx.getStorageSync('rightId') || 0,
- list: [],
- list1: [
- {
- "pagePath": "../home/home",
- "text": "首页",
- "iconPath": "/img/index_unaction.png",
- "selectedIconPath": "/img/index_action.png"
- },
- {
- "pagePath": "../me/me",
- "text": "我的",
- "iconPath": "/img/me_unaction.png",
- "selectedIconPath": "/img/me_action.png"
- }
- ],
- list2: [
- {
- "pagePath": "../home/home",
- "text": "首页",
- "iconPath": "/img/index_unaction.png",
- "selectedIconPath": "/img/index_action.png"
- },
- {
- "pagePath": "../index/index",
- "text": "频道",
- "iconPath": "/img/index_unaction.png",
- "selectedIconPath": "/img/index_action.png"
- },
- {
- "pagePath": "../me/me",
- "text": "我的",
- "iconPath": "/img/me_unaction.png",
- "selectedIconPath": "/img/me_action.png"
- }
- ]
- },
- attached() {
- this.changeList()
- getApp().eventBus.on('rightChange', data => {
- if (data !== this.data.rightId) {
- this.setData({
- rightId: data
- })
- this.changeList()
- }
- })
- },
- detached() {
- app.eventBus.off('rightChange')
- },
- methods: {
- changeList() {
- this.setData({
- rightId: wx.getStorageSync('rightId') || 0
- })
- if (this.data.rightId === 1) {
- this.setData({
- list: this.data.list2
- })
- } else {
- this.setData({
- list: this.data.list1
- })
- }
- },
- switchTab(e) {
- const data = e.currentTarget.dataset
- const url = data.path
- console.log("点击切换"+ url);
- wx.switchTab({
- url: url,
- fail:function(e){
- console.log("点击切换失败"+ e.errMsg);
- }
- })
- }
- }
- })
|