主题
LimeSwiperDot 轮播图指示点
- 自定义轮播图指示点组件
- 插件依赖
lime-style
,lime-shared
不喜勿下
文档
安装
代码演示
基础使用
使用 position: relative
的容器包裹轮播组件和指示器组件,通过type
:指定指示器类型,可选值:
dot
:圆形指示点dot-bar
:条形指示器index
:数字索引(如 1/5)title
:文字标题模式fraction
:分式指示器(如 1/5) 通过total
属性设置指示点总数或者使用list
属性设置指示文本
html
<view style="position: relative">
<swiper style="height: 300rpx" :current="current" @change="onChange" :autoplay="true" :interval="3000">
<swiper-item class="slide slide1"><text class="text">1</text></swiper-item>
<swiper-item class="slide slide2"><text class="text">2</text></swiper-item>
<swiper-item class="slide slide3"><text class="text">3</text></swiper-item>
</swiper>
<l-swiper-dot :current="current" type="dot" :total="3" />
</view>
js
const current = ref(0)
const type = ref('dot')
const onChange = (e: UniSwiperChangeEvent) => {
current.value = e.detail.current
}
自定义颜色
使用 color
可设置文本颜色, activeColor
可设置激活状态指示点颜色,inactiveColor
默认背景色
html
<view style="position: relative">
<swiper style="height: 300rpx" :current="current" @change="onChange" :autoplay="true" :interval="3000">
<swiper-item class="slide slide1"><text class="text">1</text></swiper-item>
<swiper-item class="slide slide2"><text class="text">2</text></swiper-item>
<swiper-item class="slide slide3"><text class="text">3</text></swiper-item>
</swiper>
<l-swiper-dot activeColor="#ff6b6b" inactiveColor="#ffe66d" color="#2d3436" :current="current" type="title" :list="list" field="title" />
</view>
js
const current = ref(0)
const type = ref('dot')
const onChange = (e: UniSwiperChangeEvent) => {
current.value = e.detail.current
}
const list = [
{
title: '人生得意须尽欢,莫使金樽空对月。天生我材必有用,千金散尽还复来。',
},
{
title: '但愿人长久,千里共婵娟。',
},
{
title: '无边落木萧萧下,不尽长江滚滚来。万里悲秋常作客,百年多病独登台。',
},
]
查看示例
- 导入后直接使用这个标签查看演示效果
html
<!-- // 代码位于 uni_modules/lime-swiper-dot/compoents/lime-swiper-dot -->
<lime-swiper-dot />
插件标签
- 默认 l-swiper-dot 为 component
- 默认 lime-swiper-dot 为 demo
关于vue2的使用方式
- 插件使用了
composition-api
, 如果你希望在vue2中使用请按官方的教程vue-composition-api配置 - 关键代码是: 在main.js中 在vue2部分加上这一段即可
js
// vue2
import Vue from 'vue'
import VueCompositionAPI from '@vue/composition-api'
Vue.use(VueCompositionAPI)
API
Props
参数 | 说明 | 类型 | 必填 | 默认值 |
---|---|---|---|---|
type | 指示器类型,可选值:dot dot-bar index title fraction | String | 否 | - |
total | 轮播项总数(非title 类型时使用) | Number | 否 | - |
current | 当前激活项索引(从0开始) | Number | 是 | - |
field | 标题类型时使用的数据字段名(仅type="title" 时生效) | String | 否 | - |
list | 数据源数组(title 类型必需,其他类型可选) | Array | 否 | [] |
color | 全局文本颜色(影响所有文字) | String | 否 | - |
activeColor | 激活态指示器颜色 | String | 否 | - |
inactiveColor | 未激活态指示器颜色 | String | 否 | - |
fontSize | 文字字号(带单位) | String | 否 | - |
主题定制
样式变量
组件提供了下列 CSS 变量,可用于自定义样式,uvue app不支持。
名称 | 默认值 | 描述 |
---|---|---|
--l-swiper-dot-fraction-right | $spacer-sm | 分式指示器右侧定位偏移量 |
--l-swiper-dot-fraction-bottom | $spacer-sm | 分式指示器底部定位偏移量 |
--l-swiper-dot-fraction-padding | $spacer-tn $spacer-xs | 分式指示器内边距 |
--l-swiper-dot-title-padding | $spacer-xs $spacer-xs | 标题类型指示器内边距 |
--l-swiper-dot-radius | $border-radius-hg | 指示器圆角半径 |
--l-swiper-dot-text-color | white | 指示器文字颜色 |
--l-swiper-dot-bg-color | rgba(0,0,0,0.3) | 指示器默认背景色 |
--l-swiper-dot-active-bg-color | rgba(0,0,0,0.5) | 激活状态指示器背景色 |
--l-swiper-dot-font-size | $font-size | 指示器文字基准字号 |
--l-swiper-dot-line-height | $line-height | 指示器文字行高 |
--l-swiper-dot-index-size | 40rpx | 数字索引指示器尺寸 |
--l-swiper-dot-gap | 5rpx | 指示点之间的间隔 |
--l-swiper-dot-size | 12rpx | 常规指示点尺寸 |
--l-swiper-dot-active-size | 24rpx | 激活状态指示点尺寸 |
打赏
如果你觉得本插件,解决了你的问题,赠人玫瑰,手留余香。