From 35578647449bfecbeb91b411942f6371e1d832fb Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Fri, 3 Apr 2020 14:52:46 +0800 Subject: [PATCH] fix(mp-toutiao): clean up vms --- packages/uni-mp-toutiao/dist/index.js | 15 +++++++++++++-- .../mp-toutiao/runtime/wrapper/page-parser.js | 14 +++++++++++++- src/platforms/mp-toutiao/runtime/wrapper/util.js | 4 ++-- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/packages/uni-mp-toutiao/dist/index.js b/packages/uni-mp-toutiao/dist/index.js index 666b02e8ac..8cc806ac4f 100644 --- a/packages/uni-mp-toutiao/dist/index.js +++ b/packages/uni-mp-toutiao/dist/index.js @@ -231,13 +231,13 @@ const promiseInterceptor = { }; const SYNC_API_RE = - /^\$|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/; + /^\$|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/; const CONTEXT_API_RE = /^create|Manager$/; const ASYNC_API = ['createBLEConnection']; -const CALLBACK_API_RE = /^on/; +const CALLBACK_API_RE = /^on|^off/; function isContextApi (name) { return CONTEXT_API_RE.test(name) @@ -1699,6 +1699,17 @@ function parsePage (vuePageOptions) { } else { this.is && console.warn(this.is + ' is not ready'); } + }; + + pageOptions.lifetimes.detached = function detached () { + this.$vm && this.$vm.$destroy(); + // 清理 + const webviewId = this.__webviewId__; + webviewId && Object.keys(instances).forEach(key => { + if (key.indexOf(webviewId + '_') === 0) { + delete instances[key]; + } + }); }; return pageOptions diff --git a/src/platforms/mp-toutiao/runtime/wrapper/page-parser.js b/src/platforms/mp-toutiao/runtime/wrapper/page-parser.js index 26959e8d61..6598851b0a 100644 --- a/src/platforms/mp-toutiao/runtime/wrapper/page-parser.js +++ b/src/platforms/mp-toutiao/runtime/wrapper/page-parser.js @@ -1,5 +1,6 @@ import { - isPage, + isPage, + instances, initRelation } from './util' @@ -21,6 +22,17 @@ export default function parsePage (vuePageOptions) { } else { this.is && console.warn(this.is + ' is not ready') } + } + + pageOptions.lifetimes.detached = function detached () { + this.$vm && this.$vm.$destroy() + // 清理 + const webviewId = this.__webviewId__ + webviewId && Object.keys(instances).forEach(key => { + if (key.indexOf(webviewId + '_') === 0) { + delete instances[key] + } + }) } return pageOptions diff --git a/src/platforms/mp-toutiao/runtime/wrapper/util.js b/src/platforms/mp-toutiao/runtime/wrapper/util.js index 87dc0989ab..01980a0cca 100644 --- a/src/platforms/mp-toutiao/runtime/wrapper/util.js +++ b/src/platforms/mp-toutiao/runtime/wrapper/util.js @@ -51,7 +51,7 @@ export function initRefs (vm) { } } -const instances = Object.create(null) +export const instances = Object.create(null) export function initRelation ({ vuePid, @@ -101,4 +101,4 @@ export function handleLink ({ vm._isMounted = true vm.__call_hook('mounted') vm.__call_hook('onReady') -} +} -- GitLab