Skip to content

h ​

简易 DOM 创建函数,类似 hyperscript 的轻量实现。

用法 ​

ts
import { h } from '@qingpai/utils'

const el = h('span', { 'class': 'qp-badge', 'data-id': 1 }, [
  '文本',
  h('i', { class: 'qp-icon' }),
])

参数 ​

名称类型描述
tagstring标签名
attrs?Record<string, any>属性对象,经 setAttribute 写入(null / undefined 跳过)
children?Node | string | null | undefined 或其数组子节点;字符串中的 HTML 实体(如 &nbsp;)会解析为文档片段

返回值 ​

HTMLElement — 创建好的元素。

轻排编辑器 — 教育领域富文本编辑器