From b4f063446bf05b4ec16282cf5c3dfb0e54d7424f Mon Sep 17 00:00:00 2001 From: wangyaqi Date: Fri, 25 Oct 2019 18:36:49 +0800 Subject: [PATCH] =?UTF-8?q?update:=20=E8=B0=83=E6=95=B4=E7=99=BE=E5=BA=A6?= =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E7=94=9F=E5=91=BD=E5=91=A8=E6=9C=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 - .../runtime/wrapper/component-parser.js | 39 ++++++++++++------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 29f3fe7bd..37f48d8c5 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,6 @@ }, "dependencies": { "base64-arraybuffer": "^0.2.0", - "compare-versions": "^3.5.1", "intersection-observer": "^0.7.0", "safe-area-insets": "^1.4.1" }, diff --git a/src/platforms/mp-baidu/runtime/wrapper/component-parser.js b/src/platforms/mp-baidu/runtime/wrapper/component-parser.js index cc72eba60..97d18574b 100644 --- a/src/platforms/mp-baidu/runtime/wrapper/component-parser.js +++ b/src/platforms/mp-baidu/runtime/wrapper/component-parser.js @@ -1,17 +1,17 @@ -import { - hasOwn -} from 'uni-shared' - -import compareVersions from 'compare-versions' - import { - isPage, + hasOwn +} from 'uni-shared' + +import { + isPage, initRelation } from './util' import parseBaseComponent from '../../../mp-weixin/runtime/wrapper/component-base-parser' -export default function parseComponent (vueOptions) { +const newLifecycle = swan.canIUse('lifecycle-2-0') + +export default function parseComponent(vueOptions) { const componentOptions = parseBaseComponent(vueOptions, { isPage, initRelation @@ -19,20 +19,31 @@ export default function parseComponent (vueOptions) { const oldAttached = componentOptions.lifetimes.attached - componentOptions.lifetimes.attached = function attached () { + componentOptions.lifetimes.attached = function attached() { oldAttached.call(this) if (isPage.call(this)) { // 百度 onLoad 在 attached 之前触发 // 百度 当组件作为页面时 pageinstancce 不是原来组件的 instance this.pageinstance.$vm = this.$vm - if (hasOwn(this.pageinstance, '_$args')) { + if (hasOwn(this.pageinstance, '_$args')) { this.$vm.$mp.query = this.pageinstance._$args - this.$vm.__call_hook('onLoad', this.pageinstance._$args) + this.$vm.__call_hook('onLoad', this.pageinstance._$args) delete this.pageinstance._$args } - // TODO 3.105.17以下基础库内百度 Component 作为页面时,methods 中的 onShow 不触发 - if (compareVersions.compare(swan.getEnvInfoSync().sdkVersion, '3.105.17', '<')) { - this.$vm.__call_hook('onShow') + // TODO 3.105.17以下基础库内百度 Component 作为页面时,methods 中的 onShow 不触发 + !newLifecycle && this.$vm.__call_hook('onShow') + } + } + + if (newLifecycle) { + delete componentOptions.lifetimes.ready + componentOptions.methods.onReady = function() { + if (this.$vm) { + this.$vm._isMounted = true + this.$vm.__call_hook('mounted') + this.$vm.__call_hook('onReady') + } else { + // this.is && console.warn(this.is + ' is not attached') } } } -- GitLab