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>
相关推荐
灰小猿17 分钟前
Spring前后端分离项目时间格式转换问题全局配置解决
java·前端·后端·spring·spring cloud
im_AMBER32 分钟前
React 16
前端·笔记·学习·react.js·前端框架
02苏_33 分钟前
ES6模板字符串
前端·ecmascript·es6
excel36 分钟前
⚙️ 一次性警告机制的实现:warnOnce 源码深度解析
前端
excel38 分钟前
Vue SFC 样式编译核心机制详解:compileStyle 与 PostCSS 管线设计
前端
excel39 分钟前
🧩 使用 Babel + MagicString 实现动态重写 export default 的通用方案
前端
excel39 分钟前
Vue SFC 编译器主导出文件解析:模块组织与设计哲学
前端
excel42 分钟前
深度解析:Vue SFC 模板编译器核心实现 (compileTemplate)
前端
excel43 分钟前
Vue SFC 解析器源码深度解析:从结构设计到源码映射
前端
excel1 小时前
Vue SFC 编译全景总结:从源文件到运行时组件的完整链路
前端