Category 分类
电商分类导航的双栏形态:左侧多级类目树(可展开 / 收起),右侧展示当前类的子类宫格;叶子类目展示商品位。两侧联动高亮,支持键盘树导航。
基础用法
categories 注入类目树:children 为子类目,items 为叶子商品位。
双栏联动
事件反馈
oas-change:左侧选中 / 右侧进入子类时派发,detail{ key, path, node }(path 为从根到当前类的 key 数组)oas-select:点击商品位时派发,detail{ key, item, path }
联动反馈
多级展开
左侧树支持 ↑ / ↓ 移动、→ 展开或进入首个子类、← 收起或回到父类、Enter / Space 选中;aria-expanded / aria-level 随层级同步。点击已展开的父类会收起,右侧仍保留子类宫格。
多级类目
空态
categories 缺省 / 非法 JSON / 空数组时显示空态,不抛异常。
空类目
数据契约
json
[
{
"key": "digital",
"label": "数码",
"children": [{ "key": "phone", "label": "手机", "items": [{ "key": "p1", "label": "蓝牙耳机", "meta": "热卖" }] }]
}
]key必填且全局唯一(缺省回落id/label/name)children为子类目,层级不限;items为商品位(label+ 可选meta)active-key受控:外部写入会自动展开其路径;未指定时选中第一个根类目- 同名 property 通道同效:
categories可直接赋数组(序列化后反射为 JSON attribute,读取时返回解析后的节点数组)
API
oas-category
属性
| 属性 | 说明 | 类型 | 默认值 |
|---|---|---|---|
active-key | 当前激活类目 key(受控);外部写入会自动展开其路径,缺省选第一个根类目 | string | — |
categories | 类目树(宿主注入):JSON 数组 [{ key?, id?, label?, name?, children?, items? }];key 全局唯一,children 可递归,items 为商品位 [{ key, label, meta? }] | CategoryNode[] | string | [] |
事件
| 事件 | 说明 |
|---|---|
oas-change | 左侧选中类目或从右侧进入子类时派发,detail { key, path, node }(path 为根到当前类的 key 数组) |
oas-select | 点击商品位时派发,detail |
CSS 变量
| CSS 变量 | 默认值 |
|---|---|
--oas-category-height | 24rem |
--oas-category-side-height | 12rem |
--oas-category-side-width | 9rem |