提交 17ba2fbb 编写于 作者: fxy060608's avatar fxy060608

fix(v3): improve the timing of onShow when switchTab (https://ask.dcloud.net.cn/question/90951)

上级 b6091560
...@@ -32,7 +32,7 @@ function _switchTab ({ ...@@ -32,7 +32,7 @@ function _switchTab ({
const pages = getCurrentPages() const pages = getCurrentPages()
const len = pages.length const len = pages.length
let callonShow = false let callOnShow = false
if (len >= 1) { // 前一个页面是非 tabBar 页面 if (len >= 1) { // 前一个页面是非 tabBar 页面
const currentPage = pages[len - 1] const currentPage = pages[len - 1]
...@@ -41,7 +41,7 @@ function _switchTab ({ ...@@ -41,7 +41,7 @@ function _switchTab ({
// 该情况下目标页tabBarPage的visible是不对的 // 该情况下目标页tabBarPage的visible是不对的
// 除非每次路由跳转都处理一遍tabBarPage的visible,目前仅switchTab会处理 // 除非每次路由跳转都处理一遍tabBarPage的visible,目前仅switchTab会处理
// 简单起见,暂时直接判断该情况,执行onShow // 简单起见,暂时直接判断该情况,执行onShow
callonShow = true callOnShow = true
pages.reverse().forEach(page => { pages.reverse().forEach(page => {
if (!page.$page.meta.isTabBar && page !== currentPage) { if (!page.$page.meta.isTabBar && page !== currentPage) {
page.$remove() page.$remove()
...@@ -67,8 +67,8 @@ function _switchTab ({ ...@@ -67,8 +67,8 @@ function _switchTab ({
// 查找当前 tabBarPage,且设置 visible // 查找当前 tabBarPage,且设置 visible
getCurrentPages(true).forEach(page => { getCurrentPages(true).forEach(page => {
if (('/' + page.route) === path) { if (('/' + page.route) === path) {
if (!page.$page.meta.visible || callonShow) { if (!page.$page.meta.visible) { // 之前未显示
page.$vm.__call_hook('onShow') callOnShow = true
} }
page.$page.meta.visible = true page.$page.meta.visible = true
tabBarPage = page tabBarPage = page
...@@ -81,6 +81,8 @@ function _switchTab ({ ...@@ -81,6 +81,8 @@ function _switchTab ({
if (tabBarPage) { if (tabBarPage) {
tabBarPage.$getAppWebview().show('none') tabBarPage.$getAppWebview().show('none')
// 等visible状态都切换完之后,再触发onShow,否则开发者在onShow里边 getCurrentPages 会不准确
callOnShow && tabBarPage.$vm.__call_hook('onShow')
} else { } else {
return showWebview(registerPage({ return showWebview(registerPage({
url, url,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册