spz-data-source 数据源

通用数据源组件,用于拉取商品、专辑、最近浏览等数据并提供给子组件渲染

布局

  • 需要在页面中统一管理数据来源,供 spz-render 等子组件使用时。
  • 需要展示单个商品、商品列表、专辑商品、最近浏览商品或推荐商品时。
  • 需要多个数据源嵌套,子数据源从父数据源中读取条目数据时。

通过 source-type 指定数据类型,配合 source-id 传入资源 ID,内部放置 spz-render 渲染数据内容。

<spz-data-source
  id="spz-data-source-base"
  layout="container"
  source-type="product"
  product-data='[{"title":"经典白色T恤","price":"¥199","emoji":"👕"},{"title":"休闲牛仔裤","price":"¥399","emoji":"👖"},{"title":"运动跑鞋","price":"¥599","emoji":"👟"},{"title":"时尚帆布包","price":"¥149","emoji":"👜"}]'
  items="data"
>
  <spz-render
    id="product-list-render"
    layout="container"
    binding="spz-data-source-base"
  >
    <template>
      <div class="product-grid">
        <div spz-for="item in data" class="product-card">
          <div class="product-card-img">${item.emoji}</div>
          <div class="product-card-body">
            <div class="product-card-name">${item.title}</div>
            <div class="product-card-price">${item.price}</div>
          </div>
        </div>
      </div>
    </template>
  </spz-render>
</spz-data-source>
属性名 说明 类型 默认值 是否必需
source-type 数据源类型,可选值:product(单个商品)| product-list(商品列表)| collection(专辑商品)| recently-viewed(最近浏览)| recommendation(推荐商品)| random(随机商品) string product
source-id 数据源 ID,对应商品 ID、专辑 ID 或商品 ID 列表(逗号分隔) string -
items 从返回数据中提取目标数组的路径,例如 data.list string -
product-data 直接传入商品 JSON 数据字符串,传入后不再发起网络请求 string -
page-size 每页请求的数据条数 number 40
init-page 初始请求的页码 number 0
index 当作为嵌套子数据源时,用于从父数据源中按索引取出对应条目 number -
data-random 存在此属性时强制使用随机数据(编辑模式) - -
本页目录