有人能解决这个问题吗?
自定义TabBar在基础库v2.6.2+的生命周期attached重复执行customBar代码在基础库2.6.1和2.5.0版本下运行,进入页面时先执行的customBar的生命周期函数attached,并打印了TarBar前缀的日志,然后在页面onShow函数中打印了进入某某页面日志,此时两个函数获取的当前页的WebViewId和TabBar的ExparserNodeId相同 [图片] 然而把基础库改为2.6.2+以后,BUG来了,注意时间戳,进入页面时执行customBar的attached函数和页面的onShow函数后,再次执行了customBar的attached函数,结果就是当前页的customBar显示的是上一次渲染的数据 [图片] 代码用的是你们官网提供的自定义tabbar示例代码:https://developers.weixin.qq.com/s/jiSARvmF7i55 custom-tab-bar.js [代码]lifetimes: {[代码][代码] [代码][代码]attached() {[代码][代码] [代码][代码]var[代码] [代码]curr = app.globalData.curr;[代码][代码] [代码][代码]if[代码] [代码](curr !== undefined) {[代码][代码] [代码][代码]this[代码][代码].setData({[代码][代码] [代码][代码]list: [代码][代码]this[代码][代码].data.tabs[curr][代码][代码] [代码][代码]});[代码][代码] [代码][代码]}[代码] [代码] [代码][代码]var[代码] [代码]webViewId = [代码][代码]'WebViewId: '[代码] [代码]+ [代码][代码]this[代码][代码].__wxWebviewId__;[代码][代码] [代码][代码]var[代码] [代码]nxparserNodeId = [代码][代码]'ExparserNodeId: '[代码] [代码]+ [代码][代码]this[代码][代码].__wxExparserNodeId__;[代码][代码] [代码][代码]var[代码] [代码]route = [代码][代码]''[代码][代码];[代码][代码] [代码][代码]var[代码] [代码]pages = getCurrentPages();[代码][代码] [代码][代码]if[代码] [代码](pages.length) {[代码][代码] [代码][代码]route = pages[pages.length - 1].route;[代码][代码] [代码][代码]}[代码][代码] [代码][代码]var[代码] [代码]data = JSON.stringify([代码][代码]this[代码][代码].data.list);[代码][代码] [代码][代码]console.log(Date.now(), [代码][代码]'TabBar'[代码][代码], webViewId, nxparserNodeId); [代码][代码]//, route, data);[代码][代码] [代码][代码]}[代码][代码] [代码][代码]}[代码] 角色1首页.js [代码]onShow: [代码][代码]function[代码][代码]() {[代码][代码] [代码][代码]var[代码] [代码]webViewId = [代码][代码]'WebViewId: '[代码] [代码]+ [代码][代码]this[代码][代码].__wxWebviewId__;[代码][代码] [代码][代码]var[代码] [代码]nxparserNodeId = [代码][代码]'ExparserNodeId: '[代码] [代码]+ [代码][代码]this[代码][代码].getTabBar().__wxExparserNodeId__;[代码][代码] [代码][代码]var[代码] [代码]route = [代码][代码]this[代码][代码].route;[代码][代码] [代码][代码]var[代码] [代码]data = JSON.stringify([代码][代码]this[代码][代码].getTabBar().data.list);[代码][代码] [代码][代码]console.log(Date.now(), [代码][代码]'进入角色1首页'[代码][代码], webViewId, nxparserNodeId); [代码][代码]//, route, data);[代码][代码] [代码][代码]console.log([代码][代码]' '[代码][代码]);[代码][代码] [代码][代码]if[代码] [代码]([代码][代码]typeof[代码] [代码]this[代码][代码].getTabBar === [代码][代码]'function'[代码] [代码]&& [代码][代码]this[代码][代码].getTabBar()) {[代码][代码] [代码][代码]this[代码][代码].getTabBar().setData({[代码][代码] [代码][代码]selected: 0[代码][代码] [代码][代码]})[代码][代码] [代码][代码]}[代码][代码] [代码][代码]}[代码] 角色2首页.js [代码]onShow: [代码][代码]function[代码][代码]() {[代码][代码] [代码][代码]var[代码] [代码]webViewId = [代码][代码]'WebViewId: '[代码] [代码]+ [代码][代码]this[代码][代码].__wxWebviewId__;[代码][代码] [代码][代码]var[代码] [代码]nxparserNodeId = [代码][代码]'ExparserNodeId: '[代码] [代码]+ [代码][代码]this[代码][代码].getTabBar().__wxExparserNodeId__;[代码][代码] [代码][代码]var[代码] [代码]route = [代码][代码]this[代码][代码].route;[代码][代码] [代码][代码]var[代码] [代码]data = JSON.stringify([代码][代码]this[代码][代码].getTabBar().data.list);[代码][代码] [代码][代码]console.log(Date.now(), [代码][代码]'进入角色2首页'[代码][代码], webViewId, nxparserNodeId); [代码][代码]//, route, data);[代码][代码] [代码][代码]console.log([代码][代码]' '[代码][代码]);[代码][代码] [代码][代码]if[代码] [代码]([代码][代码]typeof[代码] [代码]this[代码][代码].getTabBar === [代码][代码]'function'[代码] [代码]&& [代码][代码]this[代码][代码].getTabBar()) {[代码][代码] [代码][代码]this[代码][代码].getTabBar().setData({[代码][代码] [代码][代码]selected: 0[代码][代码] [代码][代码]})[代码][代码] [代码][代码]}[代码][代码] [代码][代码]}[代码] 个人页.js [代码]onShow: [代码][代码]function[代码][代码]() {[代码][代码] [代码][代码]var[代码] [代码]webViewId = [代码][代码]'WebViewId: '[代码] [代码]+ [代码][代码]this[代码][代码].__wxWebviewId__;[代码][代码] [代码][代码]var[代码] [代码]nxparserNodeId = [代码][代码]'ExparserNodeId: '[代码] [代码]+ [代码][代码]this[代码][代码].getTabBar().__wxExparserNodeId__;[代码][代码] [代码][代码]var[代码] [代码]route = [代码][代码]this[代码][代码].route;[代码][代码] [代码][代码]var[代码] [代码]data = JSON.stringify([代码][代码]this[代码][代码].getTabBar().data.list);[代码][代码] [代码][代码]console.log(Date.now(), [代码][代码]'进入角色'[代码] [代码]+ ([代码][代码]this[代码][代码].data.isDriver ? 1 : 2) + [代码][代码]'个人页'[代码][代码], webViewId, nxparserNodeId); [代码][代码]//, route, data);[代码][代码] [代码][代码]console.log([代码][代码]' '[代码][代码]);[代码][代码] [代码][代码]if[代码] [代码]([代码][代码]typeof[代码] [代码]this[代码][代码].getTabBar === [代码][代码]'function'[代码] [代码]&& [代码][代码]this[代码][代码].getTabBar()) {[代码][代码] [代码][代码]this[代码][代码].getTabBar().setData({[代码][代码] [代码][代码]selected: [代码][代码]this[代码][代码].data.isDriver ? 1 : 2[代码][代码] [代码][代码]})[代码][代码] [代码][代码]}[代码][代码] [代码][代码]}[代码]
2019-04-30