diff --git a/packages/uni-mp-toutiao/dist/index.js b/packages/uni-mp-toutiao/dist/index.js index 666b02e8ac47c896b7d440333803ac24af2a3df7..8cc806ac4f6d0669d3b65135886a91f9634960bb 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 26959e8d61b6c621790e5ecba6796d4771d85418..6598851b0a2982bd538f235064b7cd82f9db1f8b 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 87dc0989ab3764a1d0e18d5e99cd053ade2313ae..01980a0cca5b251dca285b3133c0f62b16eb6afe 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') -} +}