From 6aa564ef7c489ff42665d56e18eafeafd32e8933 Mon Sep 17 00:00:00 2001 From: dj <1042039504@qq.com> Date: Fri, 27 Feb 2026 20:01:20 +0800 Subject: [PATCH] =?UTF-8?q?feat(runtime):=20=E6=94=AF=E6=8C=81=E5=AF=B9?= =?UTF-8?q?=E8=B1=A1=E7=B1=BB=E5=9E=8B=E7=9A=84=E7=BB=84=E4=BB=B6=E5=88=9B?= =?UTF-8?q?=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 vnode.ts 中引入 isObject 判断函数 - 修改 createVNode 函数支持对象类型组件的 shapeFlag 设置 - 更新 h-component.html 示例代码,使用 h 函数创建组件 - 新增 h-component-video-test.html 测试文件包含原始 vnode 创建方式 - 移除手动创建 vnode 对象的硬编码方式,统一使用 h 函数创建 --- packages/runtime-core/src/vnode.ts | 14 ++++++- .../runtime/h-component-video-test.html | 38 +++++++++++++++++++ .../vue/examples/runtime/h-component.html | 26 +++---------- 3 files changed, 56 insertions(+), 22 deletions(-) create mode 100644 packages/vue/examples/runtime/h-component-video-test.html diff --git a/packages/runtime-core/src/vnode.ts b/packages/runtime-core/src/vnode.ts index b007dfb..5ce3b7d 100644 --- a/packages/runtime-core/src/vnode.ts +++ b/packages/runtime-core/src/vnode.ts @@ -1,4 +1,10 @@ -import { isArray, isFunction, isString, ShapeFlags } from '@vue/shared' +import { + isArray, + isFunction, + isObject, + isString, + ShapeFlags +} from '@vue/shared' export interface VNode { __v_isVNode: true @@ -11,7 +17,11 @@ export function isVNode(value): value is VNode { return value ? value.__v_isVNode === true : false } export function createVNode(type, props, children): VNode { - const shapeFlag = isString(type) ? ShapeFlags.ELEMENT : 0 + const shapeFlag = isString(type) + ? ShapeFlags.ELEMENT + : isObject(type) + ? ShapeFlags.STATEFUL_COMPONENT + : 0 return createBaseVNode(type, props, children, shapeFlag) } diff --git a/packages/vue/examples/runtime/h-component-video-test.html b/packages/vue/examples/runtime/h-component-video-test.html new file mode 100644 index 0000000..f3de7f0 --- /dev/null +++ b/packages/vue/examples/runtime/h-component-video-test.html @@ -0,0 +1,38 @@ + +
+ + +