let tabBar = { "custom": true, "backgroundColor": "#fff", "borderStyle": "black", "selectedColor": "#ED5D18", "color": "#666C7D", "list": [ { "pagePath": "/pages/index/index", "iconPath": "/static/images/hbtab_home@2x.png", "selectedIconPath": "/static/images/btab_home@2x.png", "text": "店铺" }, { "pagePath": "/pages/catalog/catalog", "iconPath": "/static/images/hbtab_classify@2x.png", "selectedIconPath": "/static/images/btab_classify@2x.png", "text": "分类" }, // { // "pagePath": "/pages/discover/discover", // "iconPath": "/static/images/btab_view@2x.png", // "selectedIconPath": "/static/images/btab_view_active@2x.png", // "keyiconPath": "/static/images/key_btab_view@2x.png", // "text": "发现", // "keynote": true // }, { "pagePath": "/pages/cart/cart", "iconPath": "/static/images/hbtab_cart@2x.png", "selectedIconPath": "/static/images/btab_cart@2x.png", "text": "购物车" }, { "pagePath": "/pages/ucenter/index/index", "iconPath": "/static/images/hbtab_my@2x.png", "selectedIconPath": "/static/images/btab_my@2x.png", "text": "我的" } ] } let selectIndex = 0 let fns = [] let setCountFns = [] global.setTabBarBadge = function(args) { setCountFns.forEach(fn => fn(args)) } Component({ data: { tips: {}, selectIndex, color: tabBar.color, selectedColor: tabBar.selectedColor, backgroundColor: tabBar.backgroundColor, borderStyle: tabBar.borderStyle, list: tabBar.list }, attached() { setCountFns.push((args) => { this.setData({ tips: { index: args.index, count: args.text } }) }) fns.push(() => this.setData({ selectIndex })) fns.forEach(fn => fn()) }, methods: { switchTab(e) { const data = e.currentTarget.dataset const url = data.path wx.switchTab({url}) this.setData({ selectIndex: data.index }) selectIndex = data.index fns.forEach(fn => fn()) } } })