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

fix(mp): support defineExpose (#3074)

上级 09fb6033
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;
......
......@@ -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
......
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;
},
......
......@@ -38,6 +38,7 @@ export {
fixProperties,
nextSetDataTick,
initSetRef,
findRefValue,
} from './runtime/util'
// protocols
......
......@@ -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
},
......
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;
},
......
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;
},
......
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;
},
......
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;
},
......
......@@ -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 };
......@@ -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 };
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;
},
......
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;
},
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册