提交 e5eb8c38 编写于 作者: fxy060608's avatar fxy060608

fix(mp): support defineExpose (#3074)

上级 09fb6033
import { isPlainObject, hasOwn, isArray, capitalize, isFunction, extend, isString, camelize } from '@vue/shared'; 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 作为插槽名称 // quickapp-webview 不能使用 default 作为插槽名称
const SLOT_DEFAULT_NAME = 'd'; const SLOT_DEFAULT_NAME = 'd';
...@@ -417,6 +417,13 @@ function initWxsCallMethods(methods, wxsCallMethods) { ...@@ -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) { function findVmByVueId(instance, vuePid) {
// 标准 vue3 中 没有 $children,定制了内核 // 标准 vue3 中 没有 $children,定制了内核
const $children = instance.$children; const $children = instance.$children;
...@@ -728,7 +735,7 @@ function handleRef(ref) { ...@@ -728,7 +735,7 @@ function handleRef(ref) {
const instance = this.$vm.$; const instance = this.$vm.$;
const refs = instance.refs === EMPTY_OBJ ? (instance.refs = {}) : instance.refs; const refs = instance.refs === EMPTY_OBJ ? (instance.refs = {}) : instance.refs;
const { setupState } = instance; const { setupState } = instance;
const refValue = ref.$vm || ref; const refValue = findRefValue(ref);
if (refName) { if (refName) {
if (isString(refName)) { if (isString(refName)) {
refs[refName] = refValue; refs[refName] = refValue;
......
...@@ -24,6 +24,7 @@ import { ...@@ -24,6 +24,7 @@ import {
initComponentInstance, initComponentInstance,
CreateComponentOptions, CreateComponentOptions,
updateComponentProps, updateComponentProps,
findRefValue,
} from '@dcloudio/uni-mp-core' } from '@dcloudio/uni-mp-core'
import { handleLink as handleBaseLink } from '@dcloudio/uni-mp-weixin' import { handleLink as handleBaseLink } from '@dcloudio/uni-mp-weixin'
...@@ -150,7 +151,7 @@ export function handleRef(this: MPComponentInstance, ref: MPComponentInstance) { ...@@ -150,7 +151,7 @@ export function handleRef(this: MPComponentInstance, ref: MPComponentInstance) {
instance.refs === EMPTY_OBJ ? (instance.refs = {}) : instance.refs instance.refs === EMPTY_OBJ ? (instance.refs = {}) : instance.refs
const { setupState } = instance const { setupState } = instance
const refValue = ref.$vm || ref const refValue = findRefValue(ref as any)
if (refName) { if (refName) {
if (isString(refName)) { if (isString(refName)) {
refs[refName] = refValue refs[refName] = refValue
......
import { isPlainObject, isArray, hasOwn, isFunction, extend, camelize } from '@vue/shared'; 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 // lifecycle
// App and Page // App and Page
...@@ -492,9 +492,16 @@ function selectAllComponents(mpInstance, selector, $refs) { ...@@ -492,9 +492,16 @@ function selectAllComponents(mpInstance, selector, $refs) {
const components = mpInstance.selectAllComponents(selector); const components = mpInstance.selectAllComponents(selector);
components.forEach((component) => { components.forEach((component) => {
const ref = component.properties.uR; 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) { function initRefs(instance, mpInstance) {
Object.defineProperty(instance, 'refs', { Object.defineProperty(instance, 'refs', {
get() { get() {
...@@ -509,7 +516,7 @@ function initRefs(instance, mpInstance) { ...@@ -509,7 +516,7 @@ function initRefs(instance, mpInstance) {
if (!$refs[ref]) { if (!$refs[ref]) {
$refs[ref] = []; $refs[ref] = [];
} }
$refs[ref].push(component.$vm || component); $refs[ref].push(findRefValue(component));
}); });
return $refs; return $refs;
}, },
......
...@@ -38,6 +38,7 @@ export { ...@@ -38,6 +38,7 @@ export {
fixProperties, fixProperties,
nextSetDataTick, nextSetDataTick,
initSetRef, initSetRef,
findRefValue,
} from './runtime/util' } from './runtime/util'
// protocols // protocols
......
...@@ -5,6 +5,8 @@ import { ...@@ -5,6 +5,8 @@ import {
ComponentPublicInstance, ComponentPublicInstance,
nextTick, nextTick,
} from 'vue' } from 'vue'
// @ts-ignore
import { getExposeProxy } from 'vue'
import { MPComponentInstance, MPComponentOptions } from './component' import { MPComponentInstance, MPComponentOptions } from './component'
...@@ -65,10 +67,18 @@ function selectAllComponents( ...@@ -65,10 +67,18 @@ function selectAllComponents(
const components = mpInstance.selectAllComponents(selector) const components = mpInstance.selectAllComponents(selector)
components.forEach((component) => { components.forEach((component) => {
const ref = component.properties.uR 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( export function initRefs(
instance: ComponentInternalInstance, instance: ComponentInternalInstance,
mpInstance: MPComponentInstance mpInstance: MPComponentInstance
...@@ -86,7 +96,7 @@ export function initRefs( ...@@ -86,7 +96,7 @@ export function initRefs(
if (!$refs[ref]) { if (!$refs[ref]) {
$refs[ref] = [] $refs[ref] = []
} }
$refs[ref].push(component.$vm || component) $refs[ref].push(findRefValue(component as MPComponentInstance))
}) })
return $refs return $refs
}, },
......
import { isPlainObject, isArray, hasOwn, isFunction, extend, camelize } from '@vue/shared'; 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'; const ON_READY$1 = 'onReady';
...@@ -487,9 +487,16 @@ function selectAllComponents(mpInstance, selector, $refs) { ...@@ -487,9 +487,16 @@ function selectAllComponents(mpInstance, selector, $refs) {
const components = mpInstance.selectAllComponents(selector); const components = mpInstance.selectAllComponents(selector);
components.forEach((component) => { components.forEach((component) => {
const ref = component.properties.uR; 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) { function initRefs(instance, mpInstance) {
Object.defineProperty(instance, 'refs', { Object.defineProperty(instance, 'refs', {
get() { get() {
...@@ -504,7 +511,7 @@ function initRefs(instance, mpInstance) { ...@@ -504,7 +511,7 @@ function initRefs(instance, mpInstance) {
if (!$refs[ref]) { if (!$refs[ref]) {
$refs[ref] = []; $refs[ref] = [];
} }
$refs[ref].push(component.$vm || component); $refs[ref].push(findRefValue(component));
}); });
return $refs; return $refs;
}, },
......
import { isPlainObject, isArray, hasOwn, isFunction, extend, camelize, isObject } from '@vue/shared'; 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'; const ON_READY$1 = 'onReady';
...@@ -486,9 +486,16 @@ function selectAllComponents(mpInstance, selector, $refs) { ...@@ -486,9 +486,16 @@ function selectAllComponents(mpInstance, selector, $refs) {
const components = mpInstance.selectAllComponents(selector); const components = mpInstance.selectAllComponents(selector);
components.forEach((component) => { components.forEach((component) => {
const ref = component.properties.uR; 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) { function initRefs(instance, mpInstance) {
Object.defineProperty(instance, 'refs', { Object.defineProperty(instance, 'refs', {
get() { get() {
...@@ -503,7 +510,7 @@ function initRefs(instance, mpInstance) { ...@@ -503,7 +510,7 @@ function initRefs(instance, mpInstance) {
if (!$refs[ref]) { if (!$refs[ref]) {
$refs[ref] = []; $refs[ref] = [];
} }
$refs[ref].push(component.$vm || component); $refs[ref].push(findRefValue(component));
}); });
return $refs; return $refs;
}, },
......
import { isPlainObject, isArray, hasOwn, isFunction, extend, camelize } from '@vue/shared'; 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'; const ON_READY$1 = 'onReady';
...@@ -483,9 +483,16 @@ function selectAllComponents(mpInstance, selector, $refs) { ...@@ -483,9 +483,16 @@ function selectAllComponents(mpInstance, selector, $refs) {
const components = mpInstance.selectAllComponents(selector); const components = mpInstance.selectAllComponents(selector);
components.forEach((component) => { components.forEach((component) => {
const ref = component.properties.uR; 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) { function initRefs(instance, mpInstance) {
Object.defineProperty(instance, 'refs', { Object.defineProperty(instance, 'refs', {
get() { get() {
...@@ -500,7 +507,7 @@ function initRefs(instance, mpInstance) { ...@@ -500,7 +507,7 @@ function initRefs(instance, mpInstance) {
if (!$refs[ref]) { if (!$refs[ref]) {
$refs[ref] = []; $refs[ref] = [];
} }
$refs[ref].push(component.$vm || component); $refs[ref].push(findRefValue(component));
}); });
return $refs; return $refs;
}, },
......
import { isPlainObject, isArray, hasOwn, isFunction, extend, camelize, isObject } from '@vue/shared'; 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'; const ON_READY$1 = 'onReady';
...@@ -486,9 +486,16 @@ function selectAllComponents(mpInstance, selector, $refs) { ...@@ -486,9 +486,16 @@ function selectAllComponents(mpInstance, selector, $refs) {
const components = mpInstance.selectAllComponents(selector); const components = mpInstance.selectAllComponents(selector);
components.forEach((component) => { components.forEach((component) => {
const ref = component.properties.uR; 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) { function initRefs(instance, mpInstance) {
Object.defineProperty(instance, 'refs', { Object.defineProperty(instance, 'refs', {
get() { get() {
...@@ -503,7 +510,7 @@ function initRefs(instance, mpInstance) { ...@@ -503,7 +510,7 @@ function initRefs(instance, mpInstance) {
if (!$refs[ref]) { if (!$refs[ref]) {
$refs[ref] = []; $refs[ref] = [];
} }
$refs[ref].push(component.$vm || component); $refs[ref].push(findRefValue(component));
}); });
return $refs; return $refs;
}, },
......
...@@ -4734,7 +4734,8 @@ function setRef$1(instance, isUnmount = false) { ...@@ -4734,7 +4734,8 @@ function setRef$1(instance, isUnmount = false) {
function findComponentPublicInstance(mpComponents, id) { function findComponentPublicInstance(mpComponents, id) {
const mpInstance = mpComponents.find(com => com && (com.properties || com.props).uI === id); const mpInstance = mpComponents.find(com => com && (com.properties || com.props).uI === id);
if (mpInstance) { if (mpInstance) {
return mpInstance.$vm; const vm = mpInstance.$vm;
return getExposeProxy(vm.$) || vm;
} }
return null; return null;
} }
...@@ -5505,4 +5506,4 @@ function createApp(rootComponent, rootProps = null) { ...@@ -5505,4 +5506,4 @@ function createApp(rootComponent, rootProps = null) {
} }
const createSSRApp = createApp; 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 };
...@@ -4734,7 +4734,8 @@ function setRef(instance, isUnmount = false) { ...@@ -4734,7 +4734,8 @@ function setRef(instance, isUnmount = false) {
function findComponentPublicInstance(mpComponents, id) { function findComponentPublicInstance(mpComponents, id) {
const mpInstance = mpComponents.find(com => com && (com.properties || com.props).uI === id); const mpInstance = mpComponents.find(com => com && (com.properties || com.props).uI === id);
if (mpInstance) { if (mpInstance) {
return mpInstance.$vm; const vm = mpInstance.$vm;
return getExposeProxy(vm.$) || vm;
} }
return null; return null;
} }
...@@ -5071,4 +5072,4 @@ function initCssVarsRender(instance, getter) { ...@@ -5071,4 +5072,4 @@ function initCssVarsRender(instance, getter) {
function withModifiers() { } function withModifiers() { }
function createVNode$1() { } 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 };
import { isPlainObject, isArray, hasOwn, isFunction, extend, camelize } from '@vue/shared'; 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 作为插槽名称 // quickapp-webview 不能使用 default 作为插槽名称
const SLOT_DEFAULT_NAME = 'd'; const SLOT_DEFAULT_NAME = 'd';
...@@ -355,9 +355,16 @@ function selectAllComponents(mpInstance, selector, $refs) { ...@@ -355,9 +355,16 @@ function selectAllComponents(mpInstance, selector, $refs) {
const components = mpInstance.selectAllComponents(selector); const components = mpInstance.selectAllComponents(selector);
components.forEach((component) => { components.forEach((component) => {
const ref = component.properties.uR; 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) { function initRefs(instance, mpInstance) {
Object.defineProperty(instance, 'refs', { Object.defineProperty(instance, 'refs', {
get() { get() {
...@@ -372,7 +379,7 @@ function initRefs(instance, mpInstance) { ...@@ -372,7 +379,7 @@ function initRefs(instance, mpInstance) {
if (!$refs[ref]) { if (!$refs[ref]) {
$refs[ref] = []; $refs[ref] = [];
} }
$refs[ref].push(component.$vm || component); $refs[ref].push(findRefValue(component));
}); });
return $refs; return $refs;
}, },
......
import { isPlainObject, isArray, hasOwn, isFunction, extend, camelize, isObject } from '@vue/shared'; 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'; const ON_READY$1 = 'onReady';
...@@ -483,9 +483,16 @@ function selectAllComponents(mpInstance, selector, $refs) { ...@@ -483,9 +483,16 @@ function selectAllComponents(mpInstance, selector, $refs) {
const components = mpInstance.selectAllComponents(selector); const components = mpInstance.selectAllComponents(selector);
components.forEach((component) => { components.forEach((component) => {
const ref = component.properties.uR; 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) { function initRefs(instance, mpInstance) {
Object.defineProperty(instance, 'refs', { Object.defineProperty(instance, 'refs', {
get() { get() {
...@@ -500,7 +507,7 @@ function initRefs(instance, mpInstance) { ...@@ -500,7 +507,7 @@ function initRefs(instance, mpInstance) {
if (!$refs[ref]) { if (!$refs[ref]) {
$refs[ref] = []; $refs[ref] = [];
} }
$refs[ref].push(component.$vm || component); $refs[ref].push(findRefValue(component));
}); });
return $refs; return $refs;
}, },
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册