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

fix(mp): support $children

上级 087bc446
......@@ -3055,8 +3055,29 @@ 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)
$watch: i => (__VUE_OPTIONS_API__ ? instanceWatch.bind(i) : NOOP),
// compat
$children: getCompatChildren
});
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;
......
......@@ -3046,8 +3046,29 @@ 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)
$watch: i => (__VUE_OPTIONS_API__ ? instanceWatch.bind(i) : NOOP),
// compat
$children: getCompatChildren
});
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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册