diff --git a/packages/uni-mp-alipay/dist/uni.mp.esm.js b/packages/uni-mp-alipay/dist/uni.mp.esm.js index aa7c7317f83f43be4288362e6708cd00d526a30d..4b2de683d6031b0c5ae46f3bea4aabc8ef7c6798 100644 --- a/packages/uni-mp-alipay/dist/uni.mp.esm.js +++ b/packages/uni-mp-alipay/dist/uni.mp.esm.js @@ -258,7 +258,12 @@ function hasHook(name) { return false; } function callHook(name, args) { - if (name === 'onLoad' && args && args.__id__) { + if (name === 'mounted') { + callHook.call(this, 'bm'); // beforeMount + this.$.isMounted = true; + name = 'm'; + } + else if (name === 'onLoad' && args && args.__id__) { this.__eventChannel__ = getEventChannel(args.__id__); delete args.__id__; } diff --git a/packages/uni-mp-baidu/dist/uni.mp.esm.js b/packages/uni-mp-baidu/dist/uni.mp.esm.js index ef517c2d999ad7767b7291eb6702f7fd7e4343e7..9e549b0e9764ce40d03e21500a8a4e3791430d57 100644 --- a/packages/uni-mp-baidu/dist/uni.mp.esm.js +++ b/packages/uni-mp-baidu/dist/uni.mp.esm.js @@ -248,7 +248,12 @@ function hasHook(name) { return false; } function callHook(name, args) { - if (name === 'onLoad' && args && args.__id__) { + if (name === 'mounted') { + callHook.call(this, 'bm'); // beforeMount + this.$.isMounted = true; + name = 'm'; + } + else if (name === 'onLoad' && args && args.__id__) { this.__eventChannel__ = getEventChannel(args.__id__); delete args.__id__; } @@ -386,15 +391,18 @@ function initWxsCallMethods(methods, wxsCallMethods) { }; }); } +function selectAllComponents(mpInstance, selector, $refs) { + const components = mpInstance.selectAllComponents(selector); + components.forEach((component) => { + const ref = component.dataset.ref; + $refs[ref] = component.$vm || component; + }); +} function initRefs(instance, mpInstance) { Object.defineProperty(instance, 'refs', { get() { const $refs = {}; - const components = mpInstance.selectAllComponents('.vue-ref'); - components.forEach((component) => { - const ref = component.dataset.ref; - $refs[ref] = component.$vm || component; - }); + selectAllComponents(mpInstance, '.vue-ref', $refs); const forComponents = mpInstance.selectAllComponents('.vue-ref-in-for'); forComponents.forEach((component) => { const ref = component.dataset.ref; diff --git a/packages/uni-mp-core/src/runtime/componentInstance.ts b/packages/uni-mp-core/src/runtime/componentInstance.ts index fb8601484a2b78873250b8ca5cc7c41a76999e71..74e66094421d825d3af9c96ab0dae0fdb3ae6207 100644 --- a/packages/uni-mp-core/src/runtime/componentInstance.ts +++ b/packages/uni-mp-core/src/runtime/componentInstance.ts @@ -211,7 +211,11 @@ function hasHook(this: ComponentPublicInstance, name: string) { } function callHook(this: ComponentPublicInstance, name: string, args?: unknown) { - if (name === 'onLoad' && args && (args as any).__id__) { + if (name === 'mounted') { + callHook.call(this, 'bm') // beforeMount + this.$.isMounted = true + name = 'm' + } else if (name === 'onLoad' && args && (args as any).__id__) { ;(this as any).__eventChannel__ = getEventChannel((args as any).__id__) delete (args as any).__id__ } diff --git a/packages/uni-mp-core/src/runtime/util.ts b/packages/uni-mp-core/src/runtime/util.ts index a0be9f2f9141d2030dac11234d3127f21bc3add8..9004fae08c9e17028caf0553c0e9bce067c0798d 100644 --- a/packages/uni-mp-core/src/runtime/util.ts +++ b/packages/uni-mp-core/src/runtime/util.ts @@ -56,6 +56,31 @@ export function initWxsCallMethods( }) } +function selectAllComponents( + mpInstance: MPComponentInstance, + selector: string, + $refs: Record +) { + const components = mpInstance.selectAllComponents(selector) + components.forEach((component) => { + const ref = component.dataset.ref + $refs[ref] = component.$vm || component + if (__PLATFORM__ === 'mp-weixin') { + if (component.dataset.vueGeneric === 'scoped') { + component + .selectAllComponents('.scoped-ref') + .forEach((scopedComponent) => { + selectAllComponents( + scopedComponent as MPComponentInstance, + selector, + $refs + ) + }) + } + } + }) +} + export function initRefs( instance: ComponentInternalInstance, mpInstance: MPComponentInstance @@ -63,11 +88,7 @@ export function initRefs( Object.defineProperty(instance, 'refs', { get() { const $refs: Record = {} - const components = mpInstance.selectAllComponents('.vue-ref') - components.forEach((component) => { - const ref = component.dataset.ref - $refs[ref] = component.$vm || component - }) + selectAllComponents(mpInstance, '.vue-ref', $refs) const forComponents = mpInstance.selectAllComponents('.vue-ref-in-for') forComponents.forEach((component) => { const ref = component.dataset.ref diff --git a/packages/uni-mp-qq/dist/uni.mp.esm.js b/packages/uni-mp-qq/dist/uni.mp.esm.js index ec0e18d956263dc2f762318432a0c7c9c0af52aa..5ecb45d1f1644d8b68eaeb4d38fbfa80c03c1ab9 100644 --- a/packages/uni-mp-qq/dist/uni.mp.esm.js +++ b/packages/uni-mp-qq/dist/uni.mp.esm.js @@ -248,7 +248,12 @@ function hasHook(name) { return false; } function callHook(name, args) { - if (name === 'onLoad' && args && args.__id__) { + if (name === 'mounted') { + callHook.call(this, 'bm'); // beforeMount + this.$.isMounted = true; + name = 'm'; + } + else if (name === 'onLoad' && args && args.__id__) { this.__eventChannel__ = getEventChannel(args.__id__); delete args.__id__; } @@ -386,15 +391,18 @@ function initWxsCallMethods(methods, wxsCallMethods) { }; }); } +function selectAllComponents(mpInstance, selector, $refs) { + const components = mpInstance.selectAllComponents(selector); + components.forEach((component) => { + const ref = component.dataset.ref; + $refs[ref] = component.$vm || component; + }); +} function initRefs(instance, mpInstance) { Object.defineProperty(instance, 'refs', { get() { const $refs = {}; - const components = mpInstance.selectAllComponents('.vue-ref'); - components.forEach((component) => { - const ref = component.dataset.ref; - $refs[ref] = component.$vm || component; - }); + selectAllComponents(mpInstance, '.vue-ref', $refs); const forComponents = mpInstance.selectAllComponents('.vue-ref-in-for'); forComponents.forEach((component) => { const ref = component.dataset.ref; diff --git a/packages/uni-mp-toutiao/dist/uni.mp.esm.js b/packages/uni-mp-toutiao/dist/uni.mp.esm.js index 912f6bfca61e860b3bddae50517f4f69fd74c43c..a10aceaa4240560569375cf29f9df118c7639afc 100644 --- a/packages/uni-mp-toutiao/dist/uni.mp.esm.js +++ b/packages/uni-mp-toutiao/dist/uni.mp.esm.js @@ -248,7 +248,12 @@ function hasHook(name) { return false; } function callHook(name, args) { - if (name === 'onLoad' && args && args.__id__) { + if (name === 'mounted') { + callHook.call(this, 'bm'); // beforeMount + this.$.isMounted = true; + name = 'm'; + } + else if (name === 'onLoad' && args && args.__id__) { this.__eventChannel__ = getEventChannel(args.__id__); delete args.__id__; } @@ -389,15 +394,18 @@ function initWxsCallMethods(methods, wxsCallMethods) { }; }); } +function selectAllComponents(mpInstance, selector, $refs) { + const components = mpInstance.selectAllComponents(selector); + components.forEach((component) => { + const ref = component.dataset.ref; + $refs[ref] = component.$vm || component; + }); +} function initRefs(instance, mpInstance) { Object.defineProperty(instance, 'refs', { get() { const $refs = {}; - const components = mpInstance.selectAllComponents('.vue-ref'); - components.forEach((component) => { - const ref = component.dataset.ref; - $refs[ref] = component.$vm || component; - }); + selectAllComponents(mpInstance, '.vue-ref', $refs); const forComponents = mpInstance.selectAllComponents('.vue-ref-in-for'); forComponents.forEach((component) => { const ref = component.dataset.ref; diff --git a/packages/uni-mp-vue/dist/vue.runtime.esm.js b/packages/uni-mp-vue/dist/vue.runtime.esm.js index 603a3baadfb45a2d8d1362136c90762d15c7d65a..30ffc94b53b23f7ff72f1d515bab3ffa30f4b397 100644 --- a/packages/uni-mp-vue/dist/vue.runtime.esm.js +++ b/packages/uni-mp-vue/dist/vue.runtime.esm.js @@ -1,13 +1,6 @@ -import { isSymbol, extend, isMap, isObject, toRawType, def, isArray, isString, isFunction, isPromise, toHandlerKey, remove, EMPTY_OBJ, camelize, capitalize, normalizeClass, normalizeStyle, isOn, NOOP, isGloballyWhitelisted, isIntegerKey, hasOwn, hasChanged, invokeArrayFns as invokeArrayFns$1, makeMap, isSet, NO, toNumber, hyphenate, isReservedProp, EMPTY_ARR, toTypeString } from '@vue/shared'; +import { isSymbol, extend, isMap, isObject, toRawType, def, isArray, isString, isFunction, isPromise, toHandlerKey, remove, EMPTY_OBJ, camelize, capitalize, normalizeClass, normalizeStyle, isOn, NOOP, isGloballyWhitelisted, isIntegerKey, hasOwn, hasChanged, invokeArrayFns, makeMap, isSet, NO, toNumber, hyphenate, isReservedProp, EMPTY_ARR, toTypeString } from '@vue/shared'; export { camelize } from '@vue/shared'; -const invokeArrayFns = (fns, arg) => { - let ret; - for (let i = 0; i < fns.length; i++) { - ret = fns[i](arg); - } - return ret; -}; const ON_ERROR = 'onError'; const targetMap = new WeakMap(); @@ -3055,29 +3048,8 @@ const publicPropertiesMap = extend(Object.create(null), { $options: i => (__VUE_OPTIONS_API__ ? resolveMergedOptions(i) : i.type), $forceUpdate: i => () => queueJob(i.update), // $nextTick: i => nextTick.bind(i.proxy!), // fixed by xxxxxx - $watch: i => (__VUE_OPTIONS_API__ ? instanceWatch.bind(i) : NOOP), - // compat - $children: getCompatChildren + $watch: i => (__VUE_OPTIONS_API__ ? instanceWatch.bind(i) : NOOP) }); -function getCompatChildren(instance) { - const root = instance.subTree; - const children = []; - if (root) { - walk(root, children); - } - return children; -} -function walk(vnode, children) { - if (vnode.component) { - children.push(vnode.component.proxy); - } - else if (vnode.shapeFlag & 16 /* ARRAY_CHILDREN */) { - const vnodes = vnode.children; - for (let i = 0; i < vnodes.length; i++) { - walk(vnodes[i], children); - } - } -} const PublicInstanceProxyHandlers = { get({ _: instance }, key) { const { ctx, setupState, data, props, accessCache, type, appContext } = instance; @@ -3981,8 +3953,8 @@ const prodEffectOptions = { function createDevEffectOptions(instance) { return { scheduler: queueJob, - onTrack: instance.rtc ? e => invokeArrayFns$1(instance.rtc, e) : void 0, - onTrigger: instance.rtg ? e => invokeArrayFns$1(instance.rtg, e) : void 0 + onTrack: instance.rtc ? e => invokeArrayFns(instance.rtc, e) : void 0, + onTrigger: instance.rtg ? e => invokeArrayFns(instance.rtg, e) : void 0 }; } function setupRenderEffect(instance) { @@ -3998,7 +3970,7 @@ function setupRenderEffect(instance) { const { bu, u } = instance; // beforeUpdate hook if (bu) { - invokeArrayFns$1(bu); + invokeArrayFns(bu); } patch(instance); // updated hook @@ -4012,7 +3984,7 @@ function unmountComponent(instance) { const { bum, effects, update, um } = instance; // beforeUnmount hook if (bum) { - invokeArrayFns$1(bum); + invokeArrayFns(bum); } if (effects) { for (let i = 0; i < effects.length; i++) { @@ -4090,17 +4062,6 @@ function applyOptions(options, instance, publicThis) { function set(target, key, val) { return (target[key] = val); -} -function hasHook(name) { - const hooks = this.$[name]; - if (hooks && hooks.length) { - return true; - } - return false; -} -function callHook(name, args) { - const hooks = this.$[name]; - return hooks && invokeArrayFns(hooks, args); } function errorHandler(err, instance, info) { @@ -4169,11 +4130,6 @@ function initApp(app) { } const globalProperties = appConfig.globalProperties; uniIdMixin(globalProperties); - { - // 小程序,待重构,不再挂靠全局 - globalProperties.$hasHook = hasHook; - globalProperties.$callHook = callHook; - } if (__VUE_OPTIONS_API__) { globalProperties.$set = set; globalProperties.$applyOptions = applyOptions; @@ -4183,16 +4139,6 @@ function initApp(app) { var plugin = { install(app) { initApp(app); - const globalProperties = app._context.config.globalProperties; - const oldCallHook = globalProperties.$callHook; - globalProperties.$callHook = function callHook(name, args) { - if (name === 'mounted') { - oldCallHook.call(this, 'bm'); // beforeMount - this.$.isMounted = true; - name = 'm'; - } - return oldCallHook.call(this, name, args); - }; const oldMount = app.mount; app.mount = function mount(rootContainer) { const instance = oldMount.call(app, rootContainer); diff --git a/packages/uni-mp-vue/lib/vue.runtime.esm.js b/packages/uni-mp-vue/lib/vue.runtime.esm.js index 0c33a9bf38181974951c6ecc24f7eac85aceca8d..74248254e1d8b35ae9b37a1e57c21dc761f4fac5 100644 --- a/packages/uni-mp-vue/lib/vue.runtime.esm.js +++ b/packages/uni-mp-vue/lib/vue.runtime.esm.js @@ -3046,29 +3046,8 @@ const publicPropertiesMap = extend(Object.create(null), { $options: i => (__VUE_OPTIONS_API__ ? resolveMergedOptions(i) : i.type), $forceUpdate: i => () => queueJob(i.update), // $nextTick: i => nextTick.bind(i.proxy!), // fixed by xxxxxx - $watch: i => (__VUE_OPTIONS_API__ ? instanceWatch.bind(i) : NOOP), - // compat - $children: getCompatChildren + $watch: i => (__VUE_OPTIONS_API__ ? instanceWatch.bind(i) : NOOP) }); -function getCompatChildren(instance) { - const root = instance.subTree; - const children = []; - if (root) { - walk(root, children); - } - return children; -} -function walk(vnode, children) { - if (vnode.component) { - children.push(vnode.component.proxy); - } - else if (vnode.shapeFlag & 16 /* ARRAY_CHILDREN */) { - const vnodes = vnode.children; - for (let i = 0; i < vnodes.length; i++) { - walk(vnodes[i], children); - } - } -} const PublicInstanceProxyHandlers = { get({ _: instance }, key) { const { ctx, setupState, data, props, accessCache, type, appContext } = instance; diff --git a/packages/uni-mp-vue/src/plugin.ts b/packages/uni-mp-vue/src/plugin.ts index 51e0ae9f337af33ca909079c2ccb78d11c097397..18bec8980362e9fc592f71ed67c061250b9ba7f4 100644 --- a/packages/uni-mp-vue/src/plugin.ts +++ b/packages/uni-mp-vue/src/plugin.ts @@ -5,20 +5,6 @@ import { initApp } from '@dcloudio/uni-vue' export default { install(app: App) { initApp(app) - const globalProperties = app._context.config.globalProperties - const oldCallHook = globalProperties.$callHook - globalProperties.$callHook = function callHook( - name: string, - args?: unknown - ) { - if (name === 'mounted') { - oldCallHook.call(this, 'bm') // beforeMount - this.$.isMounted = true - name = 'm' - } - return oldCallHook.call(this, name, args) - } - const oldMount = app.mount app.mount = function mount(rootContainer: any) { const instance = oldMount.call(app, rootContainer) diff --git a/packages/uni-mp-weixin/dist/uni.mp.esm.js b/packages/uni-mp-weixin/dist/uni.mp.esm.js index bd897eb414b3fd467f10d91f2e157079ccbb2530..88f15a1e4240966fd2bbad4a0f59c50729cb0097 100644 --- a/packages/uni-mp-weixin/dist/uni.mp.esm.js +++ b/packages/uni-mp-weixin/dist/uni.mp.esm.js @@ -185,7 +185,12 @@ function hasHook(name) { return false; } function callHook(name, args) { - if (name === 'onLoad' && args && args.__id__) { + if (name === 'mounted') { + callHook.call(this, 'bm'); // beforeMount + this.$.isMounted = true; + name = 'm'; + } + else if (name === 'onLoad' && args && args.__id__) { this.__eventChannel__ = getEventChannel(args.__id__); delete args.__id__; } @@ -323,15 +328,27 @@ function initWxsCallMethods(methods, wxsCallMethods) { }; }); } +function selectAllComponents(mpInstance, selector, $refs) { + const components = mpInstance.selectAllComponents(selector); + components.forEach((component) => { + const ref = component.dataset.ref; + $refs[ref] = component.$vm || component; + { + if (component.dataset.vueGeneric === 'scoped') { + component + .selectAllComponents('.scoped-ref') + .forEach((scopedComponent) => { + selectAllComponents(scopedComponent, selector, $refs); + }); + } + } + }); +} function initRefs(instance, mpInstance) { Object.defineProperty(instance, 'refs', { get() { const $refs = {}; - const components = mpInstance.selectAllComponents('.vue-ref'); - components.forEach((component) => { - const ref = component.dataset.ref; - $refs[ref] = component.$vm || component; - }); + selectAllComponents(mpInstance, '.vue-ref', $refs); const forComponents = mpInstance.selectAllComponents('.vue-ref-in-for'); forComponents.forEach((component) => { const ref = component.dataset.ref; diff --git a/packages/uni-quickapp-webview/dist/uni.mp.esm.js b/packages/uni-quickapp-webview/dist/uni.mp.esm.js index d473513401e8241966f823984a24548f838f3dab..d9e14ddfd3ac916293c8c59f8f5c206d89b798b4 100644 --- a/packages/uni-quickapp-webview/dist/uni.mp.esm.js +++ b/packages/uni-quickapp-webview/dist/uni.mp.esm.js @@ -248,7 +248,12 @@ function hasHook(name) { return false; } function callHook(name, args) { - if (name === 'onLoad' && args && args.__id__) { + if (name === 'mounted') { + callHook.call(this, 'bm'); // beforeMount + this.$.isMounted = true; + name = 'm'; + } + else if (name === 'onLoad' && args && args.__id__) { this.__eventChannel__ = getEventChannel(args.__id__); delete args.__id__; } @@ -386,15 +391,18 @@ function initWxsCallMethods(methods, wxsCallMethods) { }; }); } +function selectAllComponents(mpInstance, selector, $refs) { + const components = mpInstance.selectAllComponents(selector); + components.forEach((component) => { + const ref = component.dataset.ref; + $refs[ref] = component.$vm || component; + }); +} function initRefs(instance, mpInstance) { Object.defineProperty(instance, 'refs', { get() { const $refs = {}; - const components = mpInstance.selectAllComponents('.vue-ref'); - components.forEach((component) => { - const ref = component.dataset.ref; - $refs[ref] = component.$vm || component; - }); + selectAllComponents(mpInstance, '.vue-ref', $refs); const forComponents = mpInstance.selectAllComponents('.vue-ref-in-for'); forComponents.forEach((component) => { const ref = component.dataset.ref; diff --git a/packages/uni-shared/dist/uni-shared.d.ts b/packages/uni-shared/dist/uni-shared.d.ts index 3e95889c8e1f48901b03e756f560591bac374dec..0aeb02ba88520e179b72ae6fa774bcca23b5aabb 100644 --- a/packages/uni-shared/dist/uni-shared.d.ts +++ b/packages/uni-shared/dist/uni-shared.d.ts @@ -106,10 +106,10 @@ export declare const defaultRpx2Unit: { declare type DictArray = [number, number][]; export declare class EventChannel { - id: number; + id?: number; private listener; private emitCache; - constructor(id: number, events?: NavigateToOptionEvents); + constructor(id?: number, events?: NavigateToOptionEvents); emit(eventName: string, ...args: any[]): number | undefined; on(eventName: string, fn: EventChannelListener['fn']): void; once(eventName: string, fn: EventChannelListener['fn']): void;