每一年都奔走在自己热爱里

没有人是一座孤岛,总有谁爱着你

vue实现自定义进度条

1. Vue项目没有引入element的依赖,自定义实现进度条,效果如下:

2. template代码

<div class="progress-bar">
   <div class="progress-bar-outer">
     <span class="progress-text" :style="{color: '#156edb'}">
         {{'已用 ' + this.usedMemory + ' MB / 总空间 ' + this.totalMemory + ' MB'}}
     </span>
     <div class="progress-bar-inner" :style="{backgroundColor:'#4ba5f8',width: this.usedMemory + '%'}"/>
   </div>
</div>

3. js代码 

export default {
	name: 'Index',
	data() {
	  return {
		usedMemory: '18',
		totalMemory: '100'
	  }
	},
	methods: {
	 
	}
};

4. css代码 

.progress-bar{
    display:inline-block;
    width: 100%;
    box-sizing: border-box;
    margin-top: 12px;
    margin-bottom: 18px;
  }

  .progress-bar-outer{
    width: 100%;
    border-radius: 15px;
    background-color: #e1f0ff;
    height:30px;
    align-items: center;
    display: flex;
  }

  .progress-text{
    font-size: 12px;
    display: inline-block;
    vertical-align: middle;
    position: absolute;
    margin-left: 60%;
  }

  .progress-bar-inner{
    border-radius: 15px 15px 15px 15px;
    height: 100%;
    transition: width 0.6s ease;
    text-align: right;
    line-height: 80%;
  }

posted @   helloliyh  阅读(437)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了

喜欢请打赏

扫描二维码打赏

微信打赏

点击右上角即可分享
微信分享提示