From bb599a944130ec9e93ecef9f0b01a3887fc45d6d Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Fri, 29 Mar 2019 23:58:33 +0800 Subject: [PATCH] =?UTF-8?q?fix(runtime):=20mp=E7=94=9F=E5=91=BD=E5=91=A8?= =?UTF-8?q?=E6=9C=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/uni-mp-weixin/dist/index.js | 47 ++++++++------------ packages/uni-mp-weixin/package.json | 2 +- src/core/runtime/wrapper/create-page.js | 58 ++++++++++--------------- 3 files changed, 43 insertions(+), 64 deletions(-) diff --git a/packages/uni-mp-weixin/dist/index.js b/packages/uni-mp-weixin/dist/index.js index 3a7236d7b..c1836bc36 100644 --- a/packages/uni-mp-weixin/dist/index.js +++ b/packages/uni-mp-weixin/dist/index.js @@ -562,30 +562,6 @@ const hooks$1 = [ 'onNavigationBarSearchInputClicked' ]; -function attached (VueComponent) { - - this.$vm = new VueComponent({ - mpType: 'page', - mpInstance: this - }); - - this.$vm.__call_hook('created'); - this.$vm.$mount(); -} - -function ready () { - this.$vm.__call_hook('beforeMount'); - this.$vm._isMounted = true; - this.$vm.__call_hook('mounted'); - this.$vm.__call_hook('onReady'); -} - -function detached () { - this.$vm.__call_hook('onUnload'); - { - this.$vm.$destroy(); - } -} function createPage (vueOptions) { vueOptions = vueOptions.default || vueOptions; let VueComponent; @@ -603,19 +579,32 @@ function createPage (vueOptions) { data: getData(vueOptions, Vue.prototype), lifetimes: { // 当页面作为组件时 attached () { - attached.call(this, VueComponent); + + this.$vm = new VueComponent({ + mpType: 'page', + mpInstance: this + }); + + this.$vm.__call_hook('created'); + this.$vm.$mount(); }, ready () { - ready.call(this); + this.$vm.__call_hook('beforeMount'); + this.$vm._isMounted = true; + this.$vm.__call_hook('mounted'); + this.$vm.__call_hook('onReady'); }, detached () { - detached.call(this); + this.$vm.$destroy(); } }, methods: { // 作为页面时 onLoad (args) { - this.$vm.$mp.query = args; // 又要兼容 mpvue - this.$vm.__call_hook('onLoad', args); // 开发者可能会在 onLoad 时赋值,提前到 mount 之前 + this.$vm.$mp.query = args; // 又要兼容 mpvue + this.$vm.__call_hook('onLoad', args); // 开发者可能会在 onLoad 时赋值,提前到 mount 之前 + }, + onUnload () { + this.$vm.__call_hook('onUnload'); }, __e: handleEvent, __l: handleLink diff --git a/packages/uni-mp-weixin/package.json b/packages/uni-mp-weixin/package.json index 96a99c15d..6cb77b63f 100644 --- a/packages/uni-mp-weixin/package.json +++ b/packages/uni-mp-weixin/package.json @@ -1,6 +1,6 @@ { "name": "@dcloudio/uni-mp-weixin", - "version": "0.0.921", + "version": "0.0.922", "description": "uni-app mp-weixin", "main": "dist/index.js", "scripts": { diff --git a/src/core/runtime/wrapper/create-page.js b/src/core/runtime/wrapper/create-page.js index a4f68d352..0057add4a 100644 --- a/src/core/runtime/wrapper/create-page.js +++ b/src/core/runtime/wrapper/create-page.js @@ -31,35 +31,6 @@ const hooks = [ 'onNavigationBarSearchInputClicked' ] -function attached (VueComponent) { - if (__PLATFORM__ === 'mp-baidu') { - this.$baiduComponentInstances = Object.create(null) - } - - this.$vm = new VueComponent({ - mpType: 'page', - mpInstance: this - }) - - this.$vm.__call_hook('created') - this.$vm.$mount() -} - -function ready () { - this.$vm.__call_hook('beforeMount') - this.$vm._isMounted = true - this.$vm.__call_hook('mounted') - this.$vm.__call_hook('onReady') -} - -function detached () { - this.$vm.__call_hook('onUnload') - if (__PLATFORM__ === 'mp-baidu') { // 百度组件不会在页面 unload 时触发 detached - baiduPageDestroy(this.$vm) - } else { - this.$vm.$destroy() - } -} export function createPage (vueOptions) { vueOptions = vueOptions.default || vueOptions let VueComponent @@ -77,19 +48,38 @@ export function createPage (vueOptions) { data: getData(vueOptions, Vue.prototype), lifetimes: { // 当页面作为组件时 attached () { - attached.call(this, VueComponent) + if (__PLATFORM__ === 'mp-baidu') { + this.$baiduComponentInstances = Object.create(null) + } + + this.$vm = new VueComponent({ + mpType: 'page', + mpInstance: this + }) + + this.$vm.__call_hook('created') + this.$vm.$mount() }, ready () { - ready.call(this) + this.$vm.__call_hook('beforeMount') + this.$vm._isMounted = true + this.$vm.__call_hook('mounted') + this.$vm.__call_hook('onReady') }, detached () { - detached.call(this) + this.$vm.$destroy() } }, methods: { // 作为页面时 onLoad (args) { - this.$vm.$mp.query = args // 又要兼容 mpvue - this.$vm.__call_hook('onLoad', args) // 开发者可能会在 onLoad 时赋值,提前到 mount 之前 + this.$vm.$mp.query = args // 又要兼容 mpvue + this.$vm.__call_hook('onLoad', args) // 开发者可能会在 onLoad 时赋值,提前到 mount 之前 + }, + onUnload () { + this.$vm.__call_hook('onUnload') + if (__PLATFORM__ === 'mp-baidu') { // 百度组件不会在页面 unload 时触发 detached + baiduPageDestroy(this.$vm) + } }, __e: handleEvent, __l: handleLink -- GitLab