Skip to content
12:13

TnScrollList 横向滚动

该组件一般用于同时展示多个商品、分类的场景,也可以完成左右滑动的列表

组件位置

typescript
import TnScrollList from '@tuniao/tnui-vue3-uniapp/components/scroll-list/src/scroll-list.vue'
import TnScrollList from '@tuniao/tnui-vue3-uniapp/components/scroll-list/src/scroll-list.vue'
typescript
import TnScrollList from '@/uni_modules/tuniaoui-vue3/components/scroll-list/src/scroll-list.vue'
import TnScrollList from '@/uni_modules/tuniaoui-vue3/components/scroll-list/src/scroll-list.vue'

平台差异说明

App(vue)H5微信小程序支付宝小程序...
适配中

基础使用

将需要显示的内容放在slot中即可

vue
<template>
  <TnScrollList>
    <view class="item-container">
      <view
        v-for="i in 20"
        :key="i"
        class="scroll-item tn-flex-center tn-flex-column"
      >
        <view class="empty tn-grey-light_bg" />
        <view class="title">图鸟UI</view>
      </view>
    </view>
  </TnScrollList>
</template>

<style lang="scss" scoped>
.item-container {
  position: relative;
  width: fit-content;

  display: flex;
  flex-wrap: nowrap;

  .scroll-item {
    flex-grow: 1;
    flex-shrink: 0;
    margin: 0rpx 20rpx;

    .empty {
      width: 100rpx;
      height: 100rpx;
      border-radius: 15rpx;
    }

    .title {
      margin-top: 10rpx;
    }
  }
}
</style>
<template>
  <TnScrollList>
    <view class="item-container">
      <view
        v-for="i in 20"
        :key="i"
        class="scroll-item tn-flex-center tn-flex-column"
      >
        <view class="empty tn-grey-light_bg" />
        <view class="title">图鸟UI</view>
      </view>
    </view>
  </TnScrollList>
</template>

<style lang="scss" scoped>
.item-container {
  position: relative;
  width: fit-content;

  display: flex;
  flex-wrap: nowrap;

  .scroll-item {
    flex-grow: 1;
    flex-shrink: 0;
    margin: 0rpx 20rpx;

    .empty {
      width: 100rpx;
      height: 100rpx;
      border-radius: 15rpx;
    }

    .title {
      margin-top: 10rpx;
    }
  }
}
</style>

修改指示器样式

通过indicator-colorindicator-block-color可以修改指示器的颜色和滑块的颜色,

通过indicator-widthindicator-block-width可以修改指示器和滑块的宽度,单位为px

vue
<template>
  <TnScrollList
    indicator-color="tn-blue"
    indicator-block-color="rgba(1, 190, 255, 0.8)"
    indicator-width="60"
    indicator-block-width="40"
  >
    <view class="item-container">
      <view
        v-for="i in 20"
        :key="i"
        class="scroll-item tn-flex-center tn-flex-column"
      >
        <view class="empty tn-grey-light_bg" />
        <view class="title">图鸟UI</view>
      </view>
    </view>
  </TnScrollList>
</template>
<template>
  <TnScrollList
    indicator-color="tn-blue"
    indicator-block-color="rgba(1, 190, 255, 0.8)"
    indicator-width="60"
    indicator-block-width="40"
  >
    <view class="item-container">
      <view
        v-for="i in 20"
        :key="i"
        class="scroll-item tn-flex-center tn-flex-column"
      >
        <view class="empty tn-grey-light_bg" />
        <view class="title">图鸟UI</view>
      </view>
    </view>
  </TnScrollList>
</template>

API

Props

属性名说明类型默认值可选值
indicator是否显示指示器Booleantruefalse
indicator-width指示器宽度,单位 pxNumber40-
indicator-block-width指示器滑块宽度,单位 pxNumber20-
indicator-color指示器颜色,可以使用图鸟内置的背景色、hex、rgb、rgbaString--
indicator-block-color指示器滑块颜色,可以使用图鸟内置的背景色、hex、rgb、rgbaString--

Emits

事件名说明类型
scroll-left滚动到最左边() => void
scroll-right滚动到最右边() => void

Slots

插槽名说明
default自定义滚动内容

Tuniao UI