h
2023年06月10日
一、认识
h()
创建虚拟 DOM
节点 (vnode
)。这个名字来源于许多虚拟 DOM
实现默认形成的约定。一个更准确的名称应 该是 createVnode()
,但当你需要多次使用渲染函数时,一个简短的名字会更省力。
二、语法
h(type: string | Component , props?: object | null ,children ?: Children | Slot | Slots);
-
type
: 既可以是一个字符串 (用于原生元素) 也可以是一个Vue
组件定义 -
props
: 要传递的prop
-
children
: 子节点。当创建一个组件的vnode
时,子节点必须以插槽函数进行传递。如果组件只有默认槽,可以使用单个插槽函数进行传递。否则,必须以插槽函数的对象形式来传递。