From 023dc1963636894ede39c566e8eb59d2305f52d4 Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Fri, 1 Nov 2019 17:49:05 +0800 Subject: [PATCH] fix(v3): webview.getStyle --- packages/uni-app-plus/dist/index.v3.js | 8 +++++--- src/platforms/app-plus/service/framework/page.js | 6 ++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/uni-app-plus/dist/index.v3.js b/packages/uni-app-plus/dist/index.v3.js index 86186e4d5..57c94fe60 100644 --- a/packages/uni-app-plus/dist/index.v3.js +++ b/packages/uni-app-plus/dist/index.v3.js @@ -6820,8 +6820,10 @@ var serviceContext = (function () { const pageInstance = { route, options: Object.assign({}, query || {}), - $getAppWebview () { - return webview + $getAppWebview () { + // 重要,不能直接返回 webview 对象,因为 plus 可能会被二次替换,返回的 webview 对象内部的 plus 不正确 + // 导致 webview.getStyle 等逻辑出错(旧的 webview 内部 plus 被释放) + return plus.webview.getWebviewById(webview.id) }, $page: { id: parseInt(webview.id), @@ -9575,7 +9577,7 @@ var serviceContext = (function () { return } if (isLaunchWebview) { // 首页 - // isLaunchWebviewReady = true + isLaunchWebviewReady = true; setPreloadWebview(plus.webview.getLaunchWebview()); } else if (!preloadWebview) { // preloadWebview 不存在,重新加载一下 setPreloadWebview(plus.webview.getWebviewById(pageId)); diff --git a/src/platforms/app-plus/service/framework/page.js b/src/platforms/app-plus/service/framework/page.js index c018004f1..5a2575ab5 100644 --- a/src/platforms/app-plus/service/framework/page.js +++ b/src/platforms/app-plus/service/framework/page.js @@ -67,8 +67,10 @@ export function registerPage ({ const pageInstance = { route, options: Object.assign({}, query || {}), - $getAppWebview () { - return webview + $getAppWebview () { + // 重要,不能直接返回 webview 对象,因为 plus 可能会被二次替换,返回的 webview 对象内部的 plus 不正确 + // 导致 webview.getStyle 等逻辑出错(旧的 webview 内部 plus 被释放) + return plus.webview.getWebviewById(webview.id) }, $page: { id: parseInt(webview.id), -- GitLab