Vue--进度条

挺有意思的,大家可以玩一玩儿:

前端代码如下:可以直接运行的代码。

复制代码
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>优美的进度条</title>
  <style>
    .progress {
      height: 25px;
      width: 400px;
      border-radius: 15px;
      background-color: #272425;
      border: 3px solid #272425;
      box-sizing: border-box;
      margin-bottom: 30px;
    }
    .inner {
      width: 50%;
      height: 20px;
      border-radius: 10px;
      text-align: right;
      position: relative;
      background-color: #409eff;
      background-size: 20px 20px;
      box-sizing: border-box;
      transition: all 0.5s;
    }
    .inner span {
      position: absolute;
      right: -20px;
      bottom: -25px;
    }
  </style>
</head>
<body>
  <div id="app">

    <!-- 进度条显示 -->
    <div class="progress">
      <div class="inner" :style="{ width: percent + '%'}">
        <span> {{percent}} %</span>
      </div>
    </div>

    <!-- 点击监听 -->
    <button v-if="this.percent > 0" @click="add(-10)">进度减10%</button>
    <button v-if="this.percent < 100" @click="add(10)">进度加10%</button>

  </div>

  <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
  <script>
    
    const app = new Vue({
      el: '#app',
      data: {
        percent: 50
      },
      methods: {
        add (a) {
            this.percent += a;
            //写个异步函数
            if(this.percent === 100) {
                setTimeout(function(){
                    alert('进度条完成啦!')
                }, 500)
            }
            
        }
      }
    })
  </script>
</body>
</html>
相关推荐
恋猫de小郭12 分钟前
Firebase 如何让全球 Android 和 Flutter 开发者集体 Build Fail
android·前端·flutter
墨白曦煜13 分钟前
智能体架构范式总结(React、Plan-And-Solve、Reflection)
前端·react.js·前端框架
qq_4260039616 分钟前
多语言新增语种全量测试策略的测试范围
前端·javascript·python·自动化
frjc27 分钟前
Node.js 与 npm 极简安装教程
前端·npm·node.js
IMPYLH28 分钟前
HTML 的 <main> 元素
前端·html
深念Y31 分钟前
微服务抽取路线图:从胖单体到 ARM 集群
前端·arm开发·数据库·后端·微服务·云原生·架构
阮小贰42 分钟前
干支编码的确定性实现:节气切分 + 1000 条溯源断语(附 JS 源码)
开发语言·javascript·ecmascript
雪芽蓝域zzs1 小时前
Vue3 + Vite本地模拟数据(读取 JSON 数据)
前端
亿元程序员1 小时前
还有高手?用Shader让图片中的3D圆环转起来!
前端
灯澜忆梦1 小时前
【基于GO的Web开发14】gin请求重定向
前端·后端·golang·gin