Skip to content

LimeSwiperDot 轮播图指示点

  • 自定义轮播图指示点组件
  • 插件依赖lime-style,lime-shared不喜勿下

文档

swiper-dot

安装

插件市场入口 导入即可,首次导入可能需要重新编译

代码演示

基础使用

使用 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 fractionString-
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-colorwhite指示器文字颜色
--l-swiper-dot-bg-colorrgba(0,0,0,0.3)指示器默认背景色
--l-swiper-dot-active-bg-colorrgba(0,0,0,0.5)激活状态指示器背景色
--l-swiper-dot-font-size$font-size指示器文字基准字号
--l-swiper-dot-line-height$line-height指示器文字行高
--l-swiper-dot-index-size40rpx数字索引指示器尺寸
--l-swiper-dot-gap5rpx指示点之间的间隔
--l-swiper-dot-size12rpx常规指示点尺寸
--l-swiper-dot-active-size24rpx激活状态指示点尺寸

打赏

如果你觉得本插件,解决了你的问题,赠人玫瑰,手留余香。

源代码

组件源码