spz-state

AI 摘要

  • 该页面由 cuttlefish 组件文档自动生成,优先用于补齐目录可见性与基础说明。
  • 中文正文待人工润色,当前保留英文原始文档,避免语义丢失。
  • 若原始文档缺失,请先在 cuttlefish 对应组件补充最小文档后再同步。

原始文档(英文)

状态管理组件,支持将状态持久化到 localStorage 或 sessionStorage。

Attributes

  • state-key (required) - 存储键名
  • state-type (optional) - 存储类型:localStorage(默认)或 sessionStorage
  • state-id (optional) - 默认 state_id,当方法调用未传参时使用

Methods

getData()

返回所有状态数据。

返回格式:

{
  state_id: any
}

getState(params?)

获取指定 state_id 的状态。优先级:参数 > 组件的 state-id 属性 > 返回所有状态。

参数:

  • params (optional) - state_id 字符串或参数对象 {state_id: 'value'}

返回格式:

{
  state_id: any
}

Actions

toggle

切换指定 state_id 的状态。优先级:参数 > 组件的 state-id 属性。

参数:

  • state_id (optional) - 要切换的 state_id

Events

  • stateChange - 状态变更时触发

Example

<spz-state id="insList" state-key="insListState" state-id="aaa" layout="container">
  <spz-render src="custom:insList.getState" layout="container">
    <template>
      <div>
        <div class="click" @tap="insList.toggle">click</div>
        <div class="${data['aaa'] && data['aaa'].state ? 'active' : ''}">aaaa</div>
      </div>
    </template>
  </spz-render>
</spz-state>