uniapp自定义进度条组件

目标效果

原型设计为这样的样式,但是现有的进度条组件样式都无法满足需求,于是编写组件实现。

设计引用格式为

html 复制代码
<zLineProgress :total="15" :val="7" title="你好吗" />

定义组件

html 复制代码
<template>
	<view style="height: 3.5rem; margin: 0 1em;">
		<view class="line-total" :style="'width: ' + (val / total * 100) + '%'">{{val}}</view>
		<view style="position: relative;">			
			<view class="line-base"></view>
			<view class="line-blue" :style="'width: ' + (val / total * 100) + '%'"></view>
		</view>
		<view class="line-val">
			<text>{{title}}</text>
			<text>{{total}}</text>
		</view>
	</view>
</template>

<script>
export default {
	name: 'zLineProgress',
	data() {
		return {
		}
	},
	props: {
	    // 标题
	    title: {
	        type: [String, Number],
	        default: ''
	    },
	    total: {
			type: [Number],
			default: 0
		},
		val: {
			type: [Number],
			default: 0
		}
	},
	computed: {
		
	},
	methods: {
		
	}
}
</script>

<style scoped>
.line-total {
	color: #FFB000;
	text-align: right;
	font-size: 25rpx;
	font-style: normal;
	font-weight: 700;
	line-height: normal;
}
.line-base {
	position: absolute;
	width: 100%;
	height: 3px;
	border-radius: 8px;
	background: rgba(128, 136, 142, 0.40);
}
.line-blue {
	position: absolute;
	width: 50%;
	height: 4px;
	border-radius: 8px;
	background: #1677FF;
	box-shadow: 0px 0px 4px 0px rgba(22, 119, 255, 0.50);
}
.line-val {
	display: flex;
	justify-content: space-between;
	color: #7e7e7e;
	font-size: 25rpx;
	font-weight: 50px;
	margin-top: 12rpx;
}
</style>

页面导入

js 复制代码
import zLineProgress from '../../uni_modules/z-line-progress.vue'

配置组件声明

bash 复制代码
components: {
	"zLineProgress": zLineProgress
},

然后如本文开头所示使用即可

相关推荐
小雨下雨的雨几秒前
鸿蒙PC用Electron框架——Canvas蜡笔抖动效果实现技术深度解析
前端·javascript·华为·electron·鸿蒙系统
ZC跨境爬虫1 分钟前
跟着 MDN 学CSS day_49:定位实例练习从入门到精通
前端·css·学习
前端小万1 分钟前
用AI两小时开发上架的小程序,单日新增用户173
前端·微信小程序
道友可好6 分钟前
Spec Kit:GitHub 官方出品,规范即代码
前端·人工智能·后端
木斯佳10 分钟前
前端八股文面经大全:磐松私募-27届前端实习一面(2026-05-27)·面经深度解析
前端
薛先生_09914 分钟前
声明式导航(route-link)(跳转传参)
前端
郑州光合科技余经理18 分钟前
海外版外卖系统:如何快速搭建国际化外卖平台
java·开发语言·前端·人工智能·小程序·系统架构·php
小雨下雨的雨25 分钟前
蜡笔小画家鸿蒙PC用Electron框架 - 儿童学画蜡笔画技术实现详解
前端·javascript·华为·electron·前端框架·交互·鸿蒙系统
天蓝色的鱼鱼25 分钟前
别只拿 Playwright 写测试,这三个野路子用法才是真香
前端
SoaringHeart28 分钟前
Flutter进阶|源码修改:DecorationImage 添加网络图片占位图
前端·flutter