diff --git a/packages/uni-mp-baidu/dist/index.js b/packages/uni-mp-baidu/dist/index.js index aa3132b836cfb63dbf846ba2a8611b209a1b23c6..e761164eb335c13c49f9030a5667b86674a00ba7 100644 --- a/packages/uni-mp-baidu/dist/index.js +++ b/packages/uni-mp-baidu/dist/index.js @@ -618,6 +618,10 @@ function createApp (vueOptions) { initRefs(this); initMocks(this); } + }, + created () { // 处理 injections + this.__init_injections(this); + this.__init_provide(this); } }); @@ -697,9 +701,12 @@ function createPage (vueOptions) { this.$vm = new Vue(Object.assign(vueOptions, { mpType: 'page', mpInstance: this - })); + })); + + this.$vm.__call_hook('created'); + + this.$vm.$mount(); - this.$vm.$mount(); this.$vm.__call_hook('onLoad', args); }, onReady () { @@ -722,16 +729,16 @@ function createPage (vueOptions) { return Page(pageOptions) } -function initVueComponent (mpInstace, VueComponent) { +function initVueComponent (mpInstace, VueComponent, extraOptions = {}) { if (mpInstace.$vm) { return } - const options = { + const options = Object.assign({ mpType: 'component', mpInstance: mpInstace, propsData: mpInstace.properties - }; + }, extraOptions); // 初始化 vue 实例 mpInstace.$vm = new VueComponent(options); @@ -744,9 +751,6 @@ function initVueComponent (mpInstace, VueComponent) { }); mpInstace.$vm.$scopedSlots = mpInstace.$vm.$slots = $slots; } - - // 初始化渲染数据 - mpInstace.$vm.$mount(); } function createComponent (vueOptions) { @@ -769,22 +773,11 @@ function createComponent (vueOptions) { }, ready () { initVueComponent(this, VueComponent); // 目前发现部分情况小程序 attached 不触发 + triggerLink(this); // 处理 parent,children - triggerLink(this); - - const eventId = this.dataset.eventId; - if (eventId) { - const listeners = this.$vm.$parent.$mp.listeners; - if (listeners) { - const listenerOpts = listeners[eventId]; - Object.keys(listenerOpts).forEach(eventType => { - listenerOpts[eventType].forEach(handler => { - this.$vm[handler.once ? '$once' : '$on'](eventType, handler); - }); - }); - } - } - + // 初始化渲染数据(需要等 parent,inject 都初始化完成,否则可以放到 attached 里边初始化渲染) + this.$vm.__call_hook('created'); + this.$vm.$mount(); this.$vm._isMounted = true; this.$vm.__call_hook('mounted'); this.$vm.__call_hook('onReady'); @@ -801,10 +794,10 @@ function createComponent (vueOptions) { this.$vm.__call_hook('onPageShow', args); }, hide () { - this.$vm.__call_hook('onPageHide'); + this.$vm && this.$vm.__call_hook('onPageHide'); }, resize (size) { - this.$vm.__call_hook('onPageResize', size); + this.$vm && this.$vm.__call_hook('onPageResize', size); } }, methods: { diff --git a/packages/uni-mp-baidu/package.json b/packages/uni-mp-baidu/package.json index 9bc5bca70673747d2e14e4ebdf8da1b027b60f60..3bfdeaf8e9e33c5a2a97e9beb61ca96c628cd797 100644 --- a/packages/uni-mp-baidu/package.json +++ b/packages/uni-mp-baidu/package.json @@ -1,6 +1,6 @@ { "name": "@dcloudio/uni-mp-baidu", - "version": "0.0.809", + "version": "0.0.810", "description": "uni-app mp-baidu", "main": "dist/index.js", "scripts": { diff --git a/packages/uni-mp-toutiao/dist/index.js b/packages/uni-mp-toutiao/dist/index.js index 6de4cfc3225958ebdda886464cde7d3e860f0d0e..a539466af4e57109d7c777b6dc412838ebf33d99 100644 --- a/packages/uni-mp-toutiao/dist/index.js +++ b/packages/uni-mp-toutiao/dist/index.js @@ -643,6 +643,10 @@ function createApp (vueOptions) { initRefs(this); initMocks(this); } + }, + created () { // 处理 injections + this.__init_injections(this); + this.__init_provide(this); } }); @@ -721,9 +725,12 @@ function createPage (vueOptions) { this.$vm = new Vue(Object.assign(vueOptions, { mpType: 'page', mpInstance: this - })); + })); + + this.$vm.__call_hook('created'); + + this.$vm.$mount(); - this.$vm.$mount(); this.$vm.__call_hook('onLoad', args); }, onReady () { @@ -746,16 +753,16 @@ function createPage (vueOptions) { return Page(pageOptions) } -function initVueComponent (mpInstace, VueComponent) { +function initVueComponent (mpInstace, VueComponent, extraOptions = {}) { if (mpInstace.$vm) { return } - const options = { + const options = Object.assign({ mpType: 'component', mpInstance: mpInstace, propsData: mpInstace.properties - }; + }, extraOptions); // 初始化 vue 实例 mpInstace.$vm = new VueComponent(options); @@ -768,9 +775,6 @@ function initVueComponent (mpInstace, VueComponent) { }); mpInstace.$vm.$scopedSlots = mpInstace.$vm.$slots = $slots; } - - // 初始化渲染数据 - mpInstace.$vm.$mount(); } function createComponent (vueOptions) { @@ -793,22 +797,11 @@ function createComponent (vueOptions) { }, ready () { initVueComponent(this, VueComponent); // 目前发现部分情况小程序 attached 不触发 + triggerLink(this); // 处理 parent,children - triggerLink(this); - - const eventId = this.dataset.eventId; - if (eventId) { - const listeners = this.$vm.$parent.$mp.listeners; - if (listeners) { - const listenerOpts = listeners[eventId]; - Object.keys(listenerOpts).forEach(eventType => { - listenerOpts[eventType].forEach(handler => { - this.$vm[handler.once ? '$once' : '$on'](eventType, handler); - }); - }); - } - } - + // 初始化渲染数据(需要等 parent,inject 都初始化完成,否则可以放到 attached 里边初始化渲染) + this.$vm.__call_hook('created'); + this.$vm.$mount(); this.$vm._isMounted = true; this.$vm.__call_hook('mounted'); this.$vm.__call_hook('onReady'); @@ -822,10 +815,10 @@ function createComponent (vueOptions) { this.$vm.__call_hook('onPageShow', args); }, hide () { - this.$vm.__call_hook('onPageHide'); + this.$vm && this.$vm.__call_hook('onPageHide'); }, resize (size) { - this.$vm.__call_hook('onPageResize', size); + this.$vm && this.$vm.__call_hook('onPageResize', size); } }, methods: { diff --git a/packages/uni-mp-toutiao/package.json b/packages/uni-mp-toutiao/package.json index 9125fa8e86286788e62b62f26a0c624d66c65b21..19139f08cf9bcc7d842c321fba756aa3524f81f4 100644 --- a/packages/uni-mp-toutiao/package.json +++ b/packages/uni-mp-toutiao/package.json @@ -1,6 +1,6 @@ { "name": "@dcloudio/uni-mp-toutiao", - "version": "0.0.305", + "version": "0.0.306", "description": "uni-app mp-toutiao", "main": "dist/index.js", "scripts": { diff --git a/packages/uni-mp-weixin/dist/index.js b/packages/uni-mp-weixin/dist/index.js index 0a8ef215965dfb273c8049ee67752e2a862477c8..4199175d35ad5d190c7b38486573857bf65e9a24 100644 --- a/packages/uni-mp-weixin/dist/index.js +++ b/packages/uni-mp-weixin/dist/index.js @@ -485,6 +485,10 @@ function createApp (vueOptions) { initRefs(this); initMocks(this); } + }, + created () { // 处理 injections + this.__init_injections(this); + this.__init_provide(this); } }); @@ -507,19 +511,25 @@ function createApp (vueOptions) { return vueOptions } -function triggerLink (mpInstance) { - mpInstance.triggerEvent('__l', mpInstance.$vm, { +function triggerLink (mpInstance, vueOptions) { + mpInstance.triggerEvent('__l', mpInstance.$vm || vueOptions, { bubbles: true, composed: true }); } function handleLink (event) { - if (!event.detail.$parent) { - event.detail.$parent = this.$vm; - event.detail.$parent.$children.push(event.detail); + if (event.detail.$mp) { // vm + if (!event.detail.$parent) { + event.detail.$parent = this.$vm; + event.detail.$parent.$children.push(event.detail); - event.detail.$root = this.$vm.$root; + event.detail.$root = this.$vm.$root; + } + } else { // vueOptions + if (!event.detail.parent) { + event.detail.parent = this.$vm; + } } } @@ -548,9 +558,12 @@ function createPage (vueOptions) { this.$vm = new Vue(Object.assign(vueOptions, { mpType: 'page', mpInstance: this - })); + })); + + this.$vm.__call_hook('created'); + + this.$vm.$mount(); - this.$vm.$mount(); this.$vm.__call_hook('onLoad', args); }, onReady () { @@ -573,16 +586,16 @@ function createPage (vueOptions) { return Page(pageOptions) } -function initVueComponent (mpInstace, VueComponent) { +function initVueComponent (mpInstace, VueComponent, extraOptions = {}) { if (mpInstace.$vm) { return } - const options = { + const options = Object.assign({ mpType: 'component', mpInstance: mpInstace, propsData: mpInstace.properties - }; + }, extraOptions); // 初始化 vue 实例 mpInstace.$vm = new VueComponent(options); @@ -595,9 +608,6 @@ function initVueComponent (mpInstace, VueComponent) { }); mpInstace.$vm.$scopedSlots = mpInstace.$vm.$slots = $slots; } - - // 初始化渲染数据 - mpInstace.$vm.$mount(); } function createComponent (vueOptions) { @@ -620,22 +630,11 @@ function createComponent (vueOptions) { }, ready () { initVueComponent(this, VueComponent); // 目前发现部分情况小程序 attached 不触发 + triggerLink(this); // 处理 parent,children - triggerLink(this); - - const eventId = this.dataset.eventId; - if (eventId) { - const listeners = this.$vm.$parent.$mp.listeners; - if (listeners) { - const listenerOpts = listeners[eventId]; - Object.keys(listenerOpts).forEach(eventType => { - listenerOpts[eventType].forEach(handler => { - this.$vm[handler.once ? '$once' : '$on'](eventType, handler); - }); - }); - } - } - + // 初始化渲染数据(需要等 parent,inject 都初始化完成,否则可以放到 attached 里边初始化渲染) + this.$vm.__call_hook('created'); + this.$vm.$mount(); this.$vm._isMounted = true; this.$vm.__call_hook('mounted'); this.$vm.__call_hook('onReady'); @@ -649,10 +648,10 @@ function createComponent (vueOptions) { this.$vm.__call_hook('onPageShow', args); }, hide () { - this.$vm.__call_hook('onPageHide'); + this.$vm && this.$vm.__call_hook('onPageHide'); }, resize (size) { - this.$vm.__call_hook('onPageResize', size); + this.$vm && this.$vm.__call_hook('onPageResize', size); } }, methods: { diff --git a/packages/uni-mp-weixin/package.json b/packages/uni-mp-weixin/package.json index 9525b6d8040785b549496d654cbf4b20e4221bf5..48adc02289a20a66cea8962d34ea7fafea9de67a 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.909", + "version": "0.0.910", "description": "uni-app mp-weixin", "main": "dist/index.js", "scripts": { diff --git a/src/core/runtime/wrapper/create-app.js b/src/core/runtime/wrapper/create-app.js index b805afb3f880e1bedd667fb6406c91b4ecf67ce6..e307757f6b75fa3054e9a59196efb55ccf869513 100644 --- a/src/core/runtime/wrapper/create-app.js +++ b/src/core/runtime/wrapper/create-app.js @@ -33,6 +33,10 @@ export function createApp (vueOptions) { initRefs(this) initMocks(this) } + }, + created () { // 处理 injections + this.__init_injections(this) + this.__init_provide(this) } }) diff --git a/src/core/runtime/wrapper/create-component.js b/src/core/runtime/wrapper/create-component.js index 58d4a2f0ef11bd5cdb97b792c29501e68ae7efff..a3fd10111aa9a0754317cc8cb7c9d364b85e5f2b 100644 --- a/src/core/runtime/wrapper/create-component.js +++ b/src/core/runtime/wrapper/create-component.js @@ -11,16 +11,16 @@ import { getProperties } from './util' -function initVueComponent (mpInstace, VueComponent) { +function initVueComponent (mpInstace, VueComponent, extraOptions = {}) { if (mpInstace.$vm) { return } - const options = { + const options = Object.assign({ mpType: 'component', mpInstance: mpInstace, propsData: mpInstace.properties - } + }, extraOptions) // 初始化 vue 实例 mpInstace.$vm = new VueComponent(options) @@ -33,9 +33,6 @@ function initVueComponent (mpInstace, VueComponent) { }) mpInstace.$vm.$scopedSlots = mpInstace.$vm.$slots = $slots } - - // 初始化渲染数据 - mpInstace.$vm.$mount() } export function createComponent (vueOptions) { @@ -58,22 +55,11 @@ export function createComponent (vueOptions) { }, ready () { initVueComponent(this, VueComponent) // 目前发现部分情况小程序 attached 不触发 + triggerLink(this) // 处理 parent,children - triggerLink(this) - - const eventId = this.dataset.eventId - if (eventId) { - const listeners = this.$vm.$parent.$mp.listeners - if (listeners) { - const listenerOpts = listeners[eventId] - Object.keys(listenerOpts).forEach(eventType => { - listenerOpts[eventType].forEach(handler => { - this.$vm[handler.once ? '$once' : '$on'](eventType, handler) - }) - }) - } - } - + // 初始化渲染数据(需要等 parent,inject 都初始化完成,否则可以放到 attached 里边初始化渲染) + this.$vm.__call_hook('created') + this.$vm.$mount() this.$vm._isMounted = true this.$vm.__call_hook('mounted') this.$vm.__call_hook('onReady') @@ -90,10 +76,10 @@ export function createComponent (vueOptions) { this.$vm.__call_hook('onPageShow', args) }, hide () { - this.$vm.__call_hook('onPageHide') + this.$vm && this.$vm.__call_hook('onPageHide') }, resize (size) { - this.$vm.__call_hook('onPageResize', size) + this.$vm && this.$vm.__call_hook('onPageResize', size) } }, methods: { diff --git a/src/core/runtime/wrapper/create-page.js b/src/core/runtime/wrapper/create-page.js index 0c089366fd27bf64e001cc97dfcf7483981a6ec2..388746e9939e662584bda6d3511090947dfe06b1 100644 --- a/src/core/runtime/wrapper/create-page.js +++ b/src/core/runtime/wrapper/create-page.js @@ -39,9 +39,12 @@ export function createPage (vueOptions) { this.$vm = new Vue(Object.assign(vueOptions, { mpType: 'page', mpInstance: this - })) + })) + + this.$vm.__call_hook('created') + + this.$vm.$mount() - this.$vm.$mount() this.$vm.__call_hook('onLoad', args) }, onReady () { diff --git a/src/platforms/mp-weixin/runtime/wrapper/index.js b/src/platforms/mp-weixin/runtime/wrapper/index.js index df46ca7e836453e88c4aa9c6d290de823099de48..bace4b0d1462dd1f9f5d5a837b3e32016ebe56a3 100644 --- a/src/platforms/mp-weixin/runtime/wrapper/index.js +++ b/src/platforms/mp-weixin/runtime/wrapper/index.js @@ -1,15 +1,21 @@ -export function triggerLink (mpInstance) { - mpInstance.triggerEvent('__l', mpInstance.$vm, { +export function triggerLink (mpInstance, vueOptions) { + mpInstance.triggerEvent('__l', mpInstance.$vm || vueOptions, { bubbles: true, composed: true }) } export function handleLink (event) { - if (!event.detail.$parent) { - event.detail.$parent = this.$vm - event.detail.$parent.$children.push(event.detail) + if (event.detail.$mp) { // vm + if (!event.detail.$parent) { + event.detail.$parent = this.$vm + event.detail.$parent.$children.push(event.detail) - event.detail.$root = this.$vm.$root + event.detail.$root = this.$vm.$root + } + } else { // vueOptions + if (!event.detail.parent) { + event.detail.parent = this.$vm + } } }