Skip to content

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进度环目标值number0
v-model:current进度环当前值(从上一个percent到当前percent的过渡值)number-
size进度环尺寸string120px
lineCap进度条顶端形态 , 可选值 butt roundstringround
strokeWidth进度条宽度number,string6
strokeColor进度条颜色, 若为数组即为渐变色(渐变色值仅支持hex)uvue不支持渐变string、string[]#2db7f5
trailWidth轨道环线宽度number,string6
trailColor轨道环线颜色string#eaeef2
dashboard是否为仪表盘样式booleanfalse
clockwise是否为顺时针booleantrue
duration变化过渡时间, msnumber300
max总长度(例如:max 100,percent 50 时,进度为50%)number100
canvas是否使用canvas渲染booleanfalse

打赏

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

源代码

组件源码