diff --git a/packages/uni-mp-baidu/dist/index.js b/packages/uni-mp-baidu/dist/index.js index ccc8304478150151ae0048379486b757024ecc4b..7174e4e67d995244817268fd03cca28a42ed1bfb 100644 --- a/packages/uni-mp-baidu/dist/index.js +++ b/packages/uni-mp-baidu/dist/index.js @@ -1499,6 +1499,8 @@ function parseBaseComponent (vueComponentOptions, { return [componentOptions, VueComponent] } +const newLifecycle = swan.canIUse('lifecycle-2-0'); + function parseComponent (vueOptions) { const componentOptions = parseBaseComponent(vueOptions, { isPage, @@ -1513,16 +1515,27 @@ function parseComponent (vueOptions) { // 百度 当组件作为页面时 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 目前版本 百度 Component 作为页面时,methods 中的 onShow 不触发 - 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'); + } + }; + } + componentOptions.messages = { '__l': componentOptions.methods['__l'] }; diff --git a/src/platforms/mp-baidu/runtime/wrapper/component-parser.js b/src/platforms/mp-baidu/runtime/wrapper/component-parser.js index 97d18574bce2b913b33d9f8968ff77288d4ea13c..db7a180b2008fee69222d910dad4499e8832b49a 100644 --- a/src/platforms/mp-baidu/runtime/wrapper/component-parser.js +++ b/src/platforms/mp-baidu/runtime/wrapper/component-parser.js @@ -11,7 +11,7 @@ import parseBaseComponent from '../../../mp-weixin/runtime/wrapper/component-bas const newLifecycle = swan.canIUse('lifecycle-2-0') -export default function parseComponent(vueOptions) { +export default function parseComponent (vueOptions) { const componentOptions = parseBaseComponent(vueOptions, { isPage, initRelation @@ -19,7 +19,7 @@ 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 @@ -37,7 +37,7 @@ export default function parseComponent(vueOptions) { if (newLifecycle) { delete componentOptions.lifetimes.ready - componentOptions.methods.onReady = function() { + componentOptions.methods.onReady = function () { if (this.$vm) { this.$vm._isMounted = true this.$vm.__call_hook('mounted')