const app = getApp() Component({ data: { selected: '', color: "#7A7E83", selectedColor: "#409eff", list: [{ "pagePath": "/pages/home/index", "iconPath": "/image/home1.png", "selectedIconPath": "/image/home2.png", "text": "首页" }, { "pagePath": "/pages/reserve/index", "iconPath": "/image/reserve1.png", "selectedIconPath": "/image/reserve2.png", "text": "报餐" }, { "pagePath": "/pages/news/index", "iconPath": "/image/news1.png", "selectedIconPath": "/image/news2.png", "text": "新闻" }, { "pagePath": "/pages/my/index", "iconPath": "/image/my1.png", "selectedIconPath": "/image/my2.png", "text": "我的" }] }, attached() { }, methods: { switchTab(e) { const { index, path } = e.currentTarget.dataset; if (index == 3) { wx.getStorage({ key: 'userInfo', success: function (res) { app.globalData.userInfo = res.data; wx.switchTab({ url: path }) }, fail: function (res) { wx.getUserProfile({ desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 success: (res) => { wx.setStorage({ key: "userInfo", data: res.userInfo }) app.globalData.userInfo = res.userInfo; wx.switchTab({ url: path }) } }) } }) } else { wx.switchTab({ url: path }) } // wx.switchTab({ url }) // wx.reLaunch({ url }) // this.setData({ // selected: data.index // }) } } })