进度条

image.png
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <script src="vue.js"></script>
    <style>
         *{
            margin:0;
            padding:0;
         }
         .big{
            width: 500px;
            height: 20px;
            background-color:#dedede;
            margin-top: 20px;
            margin-bottom: 20px;
         }
         .sm{
            width:0;
            height: 20px;
            background-color:red;
            transition:all 1s;
         }
         button{
            width: 100px;
            height: 50px;
         }

    </style>
</head>
<body>
    <div id="box">
        <pro @pos="pos" :w="w"></pro>
        <btn @reduce="reduce"  @add="add" :count="w"></btn>
    </div>
</body>
    <script>
       //组件通信
       Vue.component("pro",{
            props:["w"],
            template:"<div class='big' @click='pos($event)'><div class='sm' :style='{width:w+\"%\"}'></div></div>",
            methods:{
                pos:function(e){
                    var p=Math.round((e.clientX / 500) * 100);
                    this.$emit("pos",p)
                }
            }

       })
       Vue.component("btn",{
            props:["count"],
            template:"<div><button @click='reduce'>-</button><button>{{count}}</button><button @click='add'>+</button></div>",
            methods:{
                reduce:function(){
                    this.$emit("reduce")
                },
                add:function(){
                    this.$emit("add")
                },

            }
       })
       var box=new Vue({
          el:"#box",
          data:{
               w:0
          },
          methods:{
              reduce:function(){
                  this.w--;
                  if(this.w<0){
                      this.w=0;
                  }
              },
              add:function(){
                  this.w++;
                  if(this.w>100){
                      this.w=100
                  }
              },
              pos:function(a){
                  this.w=a;
              }
          }
       })

    </script>
</html>
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

友情链接更多精彩内容