提交 1fe7da54 编写于 作者: fxy060608's avatar fxy060608

fix(v3): call onShow when switchTab from a non-tabBar page to an existing...

fix(v3): call onShow when switchTab from a non-tabBar page to an existing tabBar page https://ask.dcloud.net.cn/question/90871
上级 ca18e691
......@@ -32,9 +32,16 @@ function _switchTab ({
const pages = getCurrentPages()
const len = pages.length
let callonShow = false
if (len >= 1) { // 前一个页面是非 tabBar 页面
const currentPage = pages[len - 1]
if (!currentPage.$page.meta.isTabBar) {
// 前一个页面为非 tabBar 页面时,目标tabBar需要强制触发onShow
// 该情况下目标页tabBarPage的visible是不对的
// 除非每次路由跳转都处理一遍tabBarPage的visible,目前仅switchTab会处理
// 简单起见,暂时直接判断该情况,执行onShow
callonShow = true
pages.reverse().forEach(page => {
if (!page.$page.meta.isTabBar && page !== currentPage) {
page.$remove()
......@@ -60,7 +67,7 @@ function _switchTab ({
// 查找当前 tabBarPage,且设置 visible
getCurrentPages(true).forEach(page => {
if (('/' + page.route) === path) {
if (!page.$page.meta.visible) {
if (!page.$page.meta.visible || callonShow) {
page.$vm.__call_hook('onShow')
}
page.$page.meta.visible = true
......@@ -107,4 +114,4 @@ export function switchTab ({
from
}, callbackId)
}, openType === 'appLaunch')
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册