主题
LimeCountTo 数字滚动
- 用于数字的动态效果展示
- 插件依赖
lime-shared
不喜勿下
安装
代码演示
基础用法
通过from
和to
设置数字范围
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 | 起始值 | number | 0 |
to | 目标值 | number | 0 |
precision | 精度 | number | 0 |
showSeparator | 是否显示分隔符 | boolean | false |
active | 是否自动开始动画 | boolean | true |
duration | 动画时长 | number | 2000 |
timingFunction | 动画曲线函数 | (v:number) => void | `` |
separator | 分隔符位置,可选:group4 表示万分位,group3 表示千分位 | string | group3 |
Events
事件名 | 说明 | 回调参数 |
---|---|---|
finish | 动画结束触发 | __ |
Slots
名称 | 说明 |
---|---|
formatted | 默认插槽{value:{integer, decimal, decimalSeparator}} |
打赏
如果你觉得本插件,解决了你的问题,赠人玫瑰,手留余香。