主题
LimeCircle 进度环
- 提供css3和canvas两种渲染方式的的环形进度条
- 非uvue默认使用css实现的方式,在不支持css方案的手机会自动切为canvas
- uniapp ios最好直接使用canvas,有可能部分手机为黑色
安装
基础使用
通过percent
设置需要达到的目标值,current
为达到目标值的过渡值,示如percent
为50时,从0到50之间的过渡值,由插件返回。
html
<l-circle v-model:current="modelVale" :percent="target">
<text>{{modelVale}}%</text>
</l-circle>
js
const target = ref(50)
const modelVale = ref(0)
canvas渲染
- 也可以主动设置
canvas
使用canvas方式渲染,uvue无效
html
<l-circle v-model:current="modelVale" :percent="target" canvas>
<text>{{modelVale}}%</text>
</l-circle>
js
const target = ref(50)
const modelVale = ref(0)
查看示例
导入后直接使用这个标签查看演示效果
html
// 代码位于 uni_modules/lime-circle/compoents/lime-circle
<lime-circle />
插件标签
- 默认 l-circle 为 component
- 默认 lime-circle 为 demo
关于vue2的使用方式
- 插件使用了
composition-api
, 如果你希望在vue2中使用请按官方的教程vue-composition-api配置 - 关键代码是: 在main.js中 在vue2部分加上这一段即可
js
// main.js vue2
import Vue from 'vue'
import VueCompositionAPI from '@vue/composition-api'
Vue.use(VueCompositionAPI)
使用
html
<l-circle :current.sync="modelVale" :percent="target">
<text>{{modelVale}}%</text>
</l-circle>
<button @tap="onClick(20)">+</button>
<button @tap="onClick(-20)">-</button>
js
export default {
data() {
return {
modelVale: 0,
target: 50
}
},
methods: {
onClick(number) {
this.target = Math.max(Math.min(100, this.target + number), 0)
}
}
}
API
Props
参数 | 说明 | 类型 | 默认值 |
---|---|---|---|
percent | 进度环目标值 | number | 0 |
v-model:current | 进度环当前值(从上一个percent到当前percent的过渡值) | number | - |
size | 进度环尺寸 | string | 120px |
lineCap | 进度条顶端形态 , 可选值 butt round | string | round |
strokeWidth | 进度条宽度 | number,string | 6 |
strokeColor | 进度条颜色, 若为数组即为渐变色(渐变色值仅支持hex)uvue不支持渐变 | string、string[] | #2db7f5 |
trailWidth | 轨道环线宽度 | number,string | 6 |
trailColor | 轨道环线颜色 | string | #eaeef2 |
dashboard | 是否为仪表盘样式 | boolean | false |
clockwise | 是否为顺时针 | boolean | true |
duration | 变化过渡时间, ms | number | 300 |
max | 总长度(例如:max 100,percent 50 时,进度为50%) | number | 100 |
canvas | 是否使用canvas渲染 | boolean | false |
打赏
如果你觉得本插件,解决了你的问题,赠人玫瑰,手留余香。