diff --git a/packages/uni-mp-alipay/dist/uni.mp.esm.js b/packages/uni-mp-alipay/dist/uni.mp.esm.js index a9b084eb7fd0f148191deac0c760497222ae9382..a5bccdaccbfb5be2f94c912e1a7235ae83bdd695 100644 --- a/packages/uni-mp-alipay/dist/uni.mp.esm.js +++ b/packages/uni-mp-alipay/dist/uni.mp.esm.js @@ -1,5 +1,5 @@ import { isPlainObject, hasOwn, isArray, capitalize, isFunction, extend, isString, camelize } from '@vue/shared'; -import { injectHook, ref, toRaw, findComponentPropsData, updateProps, invalidateJob, EMPTY_OBJ, isRef, setTemplateRef, pruneComponentPropsCache } from 'vue'; +import { injectHook, ref, getExposeProxy, toRaw, findComponentPropsData, updateProps, invalidateJob, EMPTY_OBJ, isRef, setTemplateRef, pruneComponentPropsCache } from 'vue'; // quickapp-webview 不能使用 default 作为插槽名称 const SLOT_DEFAULT_NAME = 'd'; @@ -417,6 +417,13 @@ function initWxsCallMethods(methods, wxsCallMethods) { }; }); } +function findRefValue(component) { + const vm = component.$vm; + if (vm) { + return getExposeProxy(vm.$) || vm; + } + return component; +} function findVmByVueId(instance, vuePid) { // 标准 vue3 中 没有 $children,定制了内核 const $children = instance.$children; @@ -728,7 +735,7 @@ function handleRef(ref) { const instance = this.$vm.$; const refs = instance.refs === EMPTY_OBJ ? (instance.refs = {}) : instance.refs; const { setupState } = instance; - const refValue = ref.$vm || ref; + const refValue = findRefValue(ref); if (refName) { if (isString(refName)) { refs[refName] = refValue; diff --git a/packages/uni-mp-alipay/src/runtime/util.ts b/packages/uni-mp-alipay/src/runtime/util.ts index f43ca140f4ee0355c95e7cf6efa76061dc076954..5f9aae34152fc2fbfaeb0e3896735affc5d5d3b3 100644 --- a/packages/uni-mp-alipay/src/runtime/util.ts +++ b/packages/uni-mp-alipay/src/runtime/util.ts @@ -24,6 +24,7 @@ import { initComponentInstance, CreateComponentOptions, updateComponentProps, + findRefValue, } from '@dcloudio/uni-mp-core' import { handleLink as handleBaseLink } from '@dcloudio/uni-mp-weixin' @@ -150,7 +151,7 @@ export function handleRef(this: MPComponentInstance, ref: MPComponentInstance) { instance.refs === EMPTY_OBJ ? (instance.refs = {}) : instance.refs const { setupState } = instance - const refValue = ref.$vm || ref + const refValue = findRefValue(ref as any) if (refName) { if (isString(refName)) { refs[refName] = refValue diff --git a/packages/uni-mp-baidu/dist/uni.mp.esm.js b/packages/uni-mp-baidu/dist/uni.mp.esm.js index 8cc71a307ab12e6086d78f89fecb928c62a78850..f9463c3349cef6b54398e9623658529c6b27cf07 100644 --- a/packages/uni-mp-baidu/dist/uni.mp.esm.js +++ b/packages/uni-mp-baidu/dist/uni.mp.esm.js @@ -1,5 +1,5 @@ import { isPlainObject, isArray, hasOwn, isFunction, extend, camelize } from '@vue/shared'; -import { injectHook, ref, nextTick, findComponentPropsData, toRaw, updateProps, invalidateJob, pruneComponentPropsCache } from 'vue'; +import { injectHook, ref, nextTick, getExposeProxy, findComponentPropsData, toRaw, updateProps, invalidateJob, pruneComponentPropsCache } from 'vue'; // lifecycle // App and Page @@ -492,9 +492,16 @@ function selectAllComponents(mpInstance, selector, $refs) { const components = mpInstance.selectAllComponents(selector); components.forEach((component) => { const ref = component.properties.uR; - $refs[ref] = component.$vm || component; + $refs[ref] = findRefValue(component); }); } +function findRefValue(component) { + const vm = component.$vm; + if (vm) { + return getExposeProxy(vm.$) || vm; + } + return component; +} function initRefs(instance, mpInstance) { Object.defineProperty(instance, 'refs', { get() { @@ -509,7 +516,7 @@ function initRefs(instance, mpInstance) { if (!$refs[ref]) { $refs[ref] = []; } - $refs[ref].push(component.$vm || component); + $refs[ref].push(findRefValue(component)); }); return $refs; }, diff --git a/packages/uni-mp-core/src/index.ts b/packages/uni-mp-core/src/index.ts index 47e33a858cde63de26873be02f2a0b4dae0e33b3..afcf81f355327759be437007dbd820372ed4439f 100644 --- a/packages/uni-mp-core/src/index.ts +++ b/packages/uni-mp-core/src/index.ts @@ -38,6 +38,7 @@ export { fixProperties, nextSetDataTick, initSetRef, + findRefValue, } from './runtime/util' // protocols diff --git a/packages/uni-mp-core/src/runtime/util.ts b/packages/uni-mp-core/src/runtime/util.ts index f4ac1a52d704cea0075af318e2a8378ea1bd20ff..a7500da16112e63dd1ee7a0592c13524134ebf91 100644 --- a/packages/uni-mp-core/src/runtime/util.ts +++ b/packages/uni-mp-core/src/runtime/util.ts @@ -5,6 +5,8 @@ import { ComponentPublicInstance, nextTick, } from 'vue' +// @ts-ignore +import { getExposeProxy } from 'vue' import { MPComponentInstance, MPComponentOptions } from './component' @@ -65,10 +67,18 @@ function selectAllComponents( const components = mpInstance.selectAllComponents(selector) components.forEach((component) => { const ref = component.properties.uR - $refs[ref] = component.$vm || component + $refs[ref] = findRefValue(component as MPComponentInstance) }) } +export function findRefValue(component: MPComponentInstance) { + const vm = component.$vm + if (vm) { + return getExposeProxy(vm.$) || vm + } + return component +} + export function initRefs( instance: ComponentInternalInstance, mpInstance: MPComponentInstance @@ -86,7 +96,7 @@ export function initRefs( if (!$refs[ref]) { $refs[ref] = [] } - $refs[ref].push(component.$vm || component) + $refs[ref].push(findRefValue(component as MPComponentInstance)) }) return $refs }, diff --git a/packages/uni-mp-kuaishou/dist/uni.mp.esm.js b/packages/uni-mp-kuaishou/dist/uni.mp.esm.js index 17576d2927f7d7145555da631d0829491a7de605..b7fce9afebd1700f11190d2483eb5d12bd3144bf 100644 --- a/packages/uni-mp-kuaishou/dist/uni.mp.esm.js +++ b/packages/uni-mp-kuaishou/dist/uni.mp.esm.js @@ -1,5 +1,5 @@ import { isPlainObject, isArray, hasOwn, isFunction, extend, camelize } from '@vue/shared'; -import { injectHook, ref, nextTick, findComponentPropsData, toRaw, updateProps, invalidateJob, pruneComponentPropsCache } from 'vue'; +import { injectHook, ref, nextTick, getExposeProxy, findComponentPropsData, toRaw, updateProps, invalidateJob, pruneComponentPropsCache } from 'vue'; const ON_READY$1 = 'onReady'; @@ -487,9 +487,16 @@ function selectAllComponents(mpInstance, selector, $refs) { const components = mpInstance.selectAllComponents(selector); components.forEach((component) => { const ref = component.properties.uR; - $refs[ref] = component.$vm || component; + $refs[ref] = findRefValue(component); }); } +function findRefValue(component) { + const vm = component.$vm; + if (vm) { + return getExposeProxy(vm.$) || vm; + } + return component; +} function initRefs(instance, mpInstance) { Object.defineProperty(instance, 'refs', { get() { @@ -504,7 +511,7 @@ function initRefs(instance, mpInstance) { if (!$refs[ref]) { $refs[ref] = []; } - $refs[ref].push(component.$vm || component); + $refs[ref].push(findRefValue(component)); }); return $refs; }, diff --git a/packages/uni-mp-lark/dist/uni.mp.esm.js b/packages/uni-mp-lark/dist/uni.mp.esm.js index ae424fdeecad986a72222bfbd9d6afe7ab776e60..c2b3891e9f0a97fa64f4390afd480686d1eb2677 100644 --- a/packages/uni-mp-lark/dist/uni.mp.esm.js +++ b/packages/uni-mp-lark/dist/uni.mp.esm.js @@ -1,5 +1,5 @@ import { isPlainObject, isArray, hasOwn, isFunction, extend, camelize, isObject } from '@vue/shared'; -import { injectHook, ref, nextTick, findComponentPropsData, toRaw, updateProps, invalidateJob, pruneComponentPropsCache } from 'vue'; +import { injectHook, ref, nextTick, getExposeProxy, findComponentPropsData, toRaw, updateProps, invalidateJob, pruneComponentPropsCache } from 'vue'; const ON_READY$1 = 'onReady'; @@ -486,9 +486,16 @@ function selectAllComponents(mpInstance, selector, $refs) { const components = mpInstance.selectAllComponents(selector); components.forEach((component) => { const ref = component.properties.uR; - $refs[ref] = component.$vm || component; + $refs[ref] = findRefValue(component); }); } +function findRefValue(component) { + const vm = component.$vm; + if (vm) { + return getExposeProxy(vm.$) || vm; + } + return component; +} function initRefs(instance, mpInstance) { Object.defineProperty(instance, 'refs', { get() { @@ -503,7 +510,7 @@ function initRefs(instance, mpInstance) { if (!$refs[ref]) { $refs[ref] = []; } - $refs[ref].push(component.$vm || component); + $refs[ref].push(findRefValue(component)); }); return $refs; }, diff --git a/packages/uni-mp-qq/dist/uni.mp.esm.js b/packages/uni-mp-qq/dist/uni.mp.esm.js index 19e71113a164bf0c3957aa3d0af5025f72f3009b..42b551e67c8a54ddc582398959a6106649b5228d 100644 --- a/packages/uni-mp-qq/dist/uni.mp.esm.js +++ b/packages/uni-mp-qq/dist/uni.mp.esm.js @@ -1,5 +1,5 @@ import { isPlainObject, isArray, hasOwn, isFunction, extend, camelize } from '@vue/shared'; -import { injectHook, ref, findComponentPropsData, toRaw, updateProps, invalidateJob, pruneComponentPropsCache } from 'vue'; +import { injectHook, ref, getExposeProxy, findComponentPropsData, toRaw, updateProps, invalidateJob, pruneComponentPropsCache } from 'vue'; const ON_READY$1 = 'onReady'; @@ -483,9 +483,16 @@ function selectAllComponents(mpInstance, selector, $refs) { const components = mpInstance.selectAllComponents(selector); components.forEach((component) => { const ref = component.properties.uR; - $refs[ref] = component.$vm || component; + $refs[ref] = findRefValue(component); }); } +function findRefValue(component) { + const vm = component.$vm; + if (vm) { + return getExposeProxy(vm.$) || vm; + } + return component; +} function initRefs(instance, mpInstance) { Object.defineProperty(instance, 'refs', { get() { @@ -500,7 +507,7 @@ function initRefs(instance, mpInstance) { if (!$refs[ref]) { $refs[ref] = []; } - $refs[ref].push(component.$vm || component); + $refs[ref].push(findRefValue(component)); }); return $refs; }, diff --git a/packages/uni-mp-toutiao/dist/uni.mp.esm.js b/packages/uni-mp-toutiao/dist/uni.mp.esm.js index a703c43ecaa089277e2db317c4516c0eff4c846d..cd6873b3cbce7d3569ee8d30c35b4fb7c301c2c4 100644 --- a/packages/uni-mp-toutiao/dist/uni.mp.esm.js +++ b/packages/uni-mp-toutiao/dist/uni.mp.esm.js @@ -1,5 +1,5 @@ import { isPlainObject, isArray, hasOwn, isFunction, extend, camelize, isObject } from '@vue/shared'; -import { injectHook, ref, nextTick, findComponentPropsData, toRaw, updateProps, invalidateJob, pruneComponentPropsCache } from 'vue'; +import { injectHook, ref, nextTick, getExposeProxy, findComponentPropsData, toRaw, updateProps, invalidateJob, pruneComponentPropsCache } from 'vue'; const ON_READY$1 = 'onReady'; @@ -486,9 +486,16 @@ function selectAllComponents(mpInstance, selector, $refs) { const components = mpInstance.selectAllComponents(selector); components.forEach((component) => { const ref = component.properties.uR; - $refs[ref] = component.$vm || component; + $refs[ref] = findRefValue(component); }); } +function findRefValue(component) { + const vm = component.$vm; + if (vm) { + return getExposeProxy(vm.$) || vm; + } + return component; +} function initRefs(instance, mpInstance) { Object.defineProperty(instance, 'refs', { get() { @@ -503,7 +510,7 @@ function initRefs(instance, mpInstance) { if (!$refs[ref]) { $refs[ref] = []; } - $refs[ref].push(component.$vm || component); + $refs[ref].push(findRefValue(component)); }); return $refs; }, diff --git a/packages/uni-mp-vue/dist/vue.runtime.esm.js b/packages/uni-mp-vue/dist/vue.runtime.esm.js index 2cd384b5b3dc196a7a45b573c1d5e91bfc6aa613..cfa5308089608ad370417098a745b74f541f03e6 100644 --- a/packages/uni-mp-vue/dist/vue.runtime.esm.js +++ b/packages/uni-mp-vue/dist/vue.runtime.esm.js @@ -4734,7 +4734,8 @@ function setRef$1(instance, isUnmount = false) { function findComponentPublicInstance(mpComponents, id) { const mpInstance = mpComponents.find(com => com && (com.properties || com.props).uI === id); if (mpInstance) { - return mpInstance.$vm; + const vm = mpInstance.$vm; + return getExposeProxy(vm.$) || vm; } return null; } @@ -5505,4 +5506,4 @@ function createApp(rootComponent, rootProps = null) { } const createSSRApp = createApp; -export { EffectScope, Fragment, ReactiveEffect, Text, c, callWithAsyncErrorHandling, callWithErrorHandling, computed, createApp, createSSRApp, createVNode$1 as createVNode, createVueApp, customRef, d, defineAsyncComponent, defineComponent, defineEmits, defineExpose, defineProps, diff, e, effect, effectScope, f, findComponentPropsData, getCurrentInstance, getCurrentScope, guardReactiveProps, h, inject, injectHook, invalidateJob, isInSSRComponentSetup, isProxy, isReactive, isReadonly, isRef, logError, markRaw, mergeDefaults, mergeProps, n, nextTick, o, onActivated, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onScopeDispose, onServerPrefetch, onUnmounted, onUpdated, p, patch, provide, proxyRefs, pruneComponentPropsCache, queuePostFlushCb, r, reactive, readonly, ref, resolveComponent, resolveDirective, resolveFilter, s, setCurrentRenderingInstance, setTemplateRef, setupDevtoolsPlugin, shallowReactive, shallowReadonly, shallowRef, sr, stop, t, toHandlers, toRaw, toRef, toRefs, triggerRef, unref, updateProps, useAttrs, useCssModule, useCssVars, useSSRContext, useSlots, version, w, warn$1 as warn, watch, watchEffect, watchPostEffect, watchSyncEffect, withAsyncContext, withCtx, withDefaults, withDirectives, withModifiers, withScopeId }; +export { EffectScope, Fragment, ReactiveEffect, Text, c, callWithAsyncErrorHandling, callWithErrorHandling, computed, createApp, createSSRApp, createVNode$1 as createVNode, createVueApp, customRef, d, defineAsyncComponent, defineComponent, defineEmits, defineExpose, defineProps, diff, e, effect, effectScope, f, findComponentPropsData, getCurrentInstance, getCurrentScope, getExposeProxy, guardReactiveProps, h, inject, injectHook, invalidateJob, isInSSRComponentSetup, isProxy, isReactive, isReadonly, isRef, logError, markRaw, mergeDefaults, mergeProps, n, nextTick, o, onActivated, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onScopeDispose, onServerPrefetch, onUnmounted, onUpdated, p, patch, provide, proxyRefs, pruneComponentPropsCache, queuePostFlushCb, r, reactive, readonly, ref, resolveComponent, resolveDirective, resolveFilter, s, setCurrentRenderingInstance, setTemplateRef, setupDevtoolsPlugin, shallowReactive, shallowReadonly, shallowRef, sr, stop, t, toHandlers, toRaw, toRef, toRefs, triggerRef, unref, updateProps, useAttrs, useCssModule, useCssVars, useSSRContext, useSlots, version, w, warn$1 as warn, watch, watchEffect, watchPostEffect, watchSyncEffect, withAsyncContext, withCtx, withDefaults, withDirectives, withModifiers, withScopeId }; diff --git a/packages/uni-mp-vue/lib/vue.runtime.esm.js b/packages/uni-mp-vue/lib/vue.runtime.esm.js index bba7b4b7656c638d6365d23ea31ae2983f681a1f..0e0f341fcc40b94b7b864c69a7b3e2718d022c2b 100644 --- a/packages/uni-mp-vue/lib/vue.runtime.esm.js +++ b/packages/uni-mp-vue/lib/vue.runtime.esm.js @@ -4734,7 +4734,8 @@ function setRef(instance, isUnmount = false) { function findComponentPublicInstance(mpComponents, id) { const mpInstance = mpComponents.find(com => com && (com.properties || com.props).uI === id); if (mpInstance) { - return mpInstance.$vm; + const vm = mpInstance.$vm; + return getExposeProxy(vm.$) || vm; } return null; } @@ -5071,4 +5072,4 @@ function initCssVarsRender(instance, getter) { function withModifiers() { } function createVNode$1() { } -export { EffectScope, Fragment, ReactiveEffect, Text, callWithAsyncErrorHandling, callWithErrorHandling, computed, createVNode$1 as createVNode, createVueApp, customRef, defineAsyncComponent, defineComponent, defineEmits, defineExpose, defineProps, diff, effect, effectScope, getCurrentInstance, getCurrentScope, guardReactiveProps, inject, injectHook, invalidateJob, isInSSRComponentSetup, isProxy, isReactive, isReadonly, isRef, logError, markRaw, mergeDefaults, mergeProps, nextTick, onActivated, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onScopeDispose, onServerPrefetch, onUnmounted, onUpdated, patch, provide, proxyRefs, queuePostFlushCb, reactive, readonly, ref, resolveComponent, resolveDirective, resolveFilter, setCurrentRenderingInstance, setTemplateRef, shallowReactive, shallowReadonly, shallowRef, stop, toHandlers, toRaw, toRef, toRefs, triggerRef, unref, updateProps, useAttrs, useCssModule, useCssVars, useSSRContext, useSlots, version, warn$1 as warn, watch, watchEffect, watchPostEffect, watchSyncEffect, withAsyncContext, withCtx, withDefaults, withDirectives, withModifiers, withScopeId }; +export { EffectScope, Fragment, ReactiveEffect, Text, callWithAsyncErrorHandling, callWithErrorHandling, computed, createVNode$1 as createVNode, createVueApp, customRef, defineAsyncComponent, defineComponent, defineEmits, defineExpose, defineProps, diff, effect, effectScope, getCurrentInstance, getCurrentScope, getExposeProxy, guardReactiveProps, inject, injectHook, invalidateJob, isInSSRComponentSetup, isProxy, isReactive, isReadonly, isRef, logError, markRaw, mergeDefaults, mergeProps, nextTick, onActivated, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onScopeDispose, onServerPrefetch, onUnmounted, onUpdated, patch, provide, proxyRefs, queuePostFlushCb, reactive, readonly, ref, resolveComponent, resolveDirective, resolveFilter, setCurrentRenderingInstance, setTemplateRef, shallowReactive, shallowReadonly, shallowRef, stop, toHandlers, toRaw, toRef, toRefs, triggerRef, unref, updateProps, useAttrs, useCssModule, useCssVars, useSSRContext, useSlots, version, warn$1 as warn, watch, watchEffect, watchPostEffect, watchSyncEffect, withAsyncContext, withCtx, withDefaults, withDirectives, withModifiers, withScopeId }; diff --git a/packages/uni-mp-weixin/dist/uni.mp.esm.js b/packages/uni-mp-weixin/dist/uni.mp.esm.js index 82d1b0e9e07031c8a8abcc948c844e1327079610..30b514776b4aa91db0b146e23feb101a76555075 100644 --- a/packages/uni-mp-weixin/dist/uni.mp.esm.js +++ b/packages/uni-mp-weixin/dist/uni.mp.esm.js @@ -1,5 +1,5 @@ import { isPlainObject, isArray, hasOwn, isFunction, extend, camelize } from '@vue/shared'; -import { injectHook, ref, findComponentPropsData, toRaw, updateProps, invalidateJob, pruneComponentPropsCache } from 'vue'; +import { injectHook, ref, getExposeProxy, findComponentPropsData, toRaw, updateProps, invalidateJob, pruneComponentPropsCache } from 'vue'; // quickapp-webview 不能使用 default 作为插槽名称 const SLOT_DEFAULT_NAME = 'd'; @@ -355,9 +355,16 @@ function selectAllComponents(mpInstance, selector, $refs) { const components = mpInstance.selectAllComponents(selector); components.forEach((component) => { const ref = component.properties.uR; - $refs[ref] = component.$vm || component; + $refs[ref] = findRefValue(component); }); } +function findRefValue(component) { + const vm = component.$vm; + if (vm) { + return getExposeProxy(vm.$) || vm; + } + return component; +} function initRefs(instance, mpInstance) { Object.defineProperty(instance, 'refs', { get() { @@ -372,7 +379,7 @@ function initRefs(instance, mpInstance) { if (!$refs[ref]) { $refs[ref] = []; } - $refs[ref].push(component.$vm || component); + $refs[ref].push(findRefValue(component)); }); return $refs; }, diff --git a/packages/uni-quickapp-webview/dist/uni.mp.esm.js b/packages/uni-quickapp-webview/dist/uni.mp.esm.js index 55d8e2b954181b39d2390bbaf7763ac90d8e397b..4fb38b80534ca8bed4f69d71b39ea4884bfe3130 100644 --- a/packages/uni-quickapp-webview/dist/uni.mp.esm.js +++ b/packages/uni-quickapp-webview/dist/uni.mp.esm.js @@ -1,5 +1,5 @@ import { isPlainObject, isArray, hasOwn, isFunction, extend, camelize, isObject } from '@vue/shared'; -import { injectHook, ref, nextTick, findComponentPropsData, toRaw, updateProps, invalidateJob, pruneComponentPropsCache } from 'vue'; +import { injectHook, ref, nextTick, getExposeProxy, findComponentPropsData, toRaw, updateProps, invalidateJob, pruneComponentPropsCache } from 'vue'; const ON_READY$1 = 'onReady'; @@ -483,9 +483,16 @@ function selectAllComponents(mpInstance, selector, $refs) { const components = mpInstance.selectAllComponents(selector); components.forEach((component) => { const ref = component.properties.uR; - $refs[ref] = component.$vm || component; + $refs[ref] = findRefValue(component); }); } +function findRefValue(component) { + const vm = component.$vm; + if (vm) { + return getExposeProxy(vm.$) || vm; + } + return component; +} function initRefs(instance, mpInstance) { Object.defineProperty(instance, 'refs', { get() { @@ -500,7 +507,7 @@ function initRefs(instance, mpInstance) { if (!$refs[ref]) { $refs[ref] = []; } - $refs[ref].push(component.$vm || component); + $refs[ref].push(findRefValue(component)); }); return $refs; },