Skip to content

LimeCountTo 数字滚动

  • 用于数字的动态效果展示
  • 插件依赖lime-shared不喜勿下

安装

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

代码演示

基础用法

通过fromto设置数字范围

html
<l-count-to :from="0" :to="12039" />

精度

通过precision可以设置小数位精度

html
<l-count-to :from="0" :to="12039" :precision="2" />

分隔符

通过show-separator可以设置是否显示分隔符

html
<l-count-to :show-separator="true" :from="0" :to="100000000" />

万分位分隔符

通过separator设置为group4显示万分位分隔符,国内习惯万分位分割

html
<l-count-to separator="group4" :show-separator="true" :from="0.0" :to="699700.699" :precision="3" />

插槽

通过formatted插槽导出的value可以更个性定制样式

html
<l-count-to :show-separator="true" :from="0.0" :to="699700.699" :precision="3">
	<template #formatted={value}>
		<text style="background-color: antiquewhite;">
			<text style="font-size: 32rpx">¥</text>
			<text style="font-size: 52rpx" :key="value.integer">{{value.integer}}</text>
			<text style="font-size: 32rpx">.</text>
			<text style="font-size: 32rpx">{{value.decimal}}</text>
		</text>
	</template>
</l-count-to>

结束的回调

通过separator设置为group4显示万分位分隔符,国内习惯万分位分割

html
<l-count-to :show-separator="true"  :from="0" :to="100000000" @finish="handleFinish" />
js
const handleFinish = () => {
	console.log('结束')
}

手动播放

通过separator设置为group4显示万分位分隔符,国内习惯万分位分割

html
<l-count-to ref="countToRef" :active="false" :show-separator="true"  :from="0" :to="100000000" />
<button size="mini" @click="play"> 播放</button>
js
const countToRef = ref<LCountToComponentPublicInstance|null>(null)

const play = () => {
	if(countToRef.value == null) return
	countToRef.value!.play()
}

查看示例

  • 导入后直接使用这个标签查看演示效果
html
 // 代码位于 uni_modules/lime-count-to/compoents/lime-count-to 
<lime-count-to />

插件标签

  • 默认 l-count-to 为 component
  • 默认 lime-count-to 为 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

参数说明类型默认值
from起始值number0
to目标值number0
precision精度number0
showSeparator是否显示分隔符booleanfalse
active是否自动开始动画booleantrue
duration动画时长number2000
timingFunction动画曲线函数(v:number) => void``
separator分隔符位置,可选:group4表示万分位,group3表示千分位stringgroup3

Events

事件名说明回调参数
finish动画结束触发__

Slots

名称说明
formatted默认插槽{value:{integer, decimal, decimalSeparator}}

打赏

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

源代码

组件源码