当前位置:编程学习 > > 正文

vue代码统计(Vue实现计数器案例)

时间:2021-10-21 07:03:32类别:编程学习

vue代码统计

Vue实现计数器案例

本文实例为大家分享了Vue实现计数器展示的具体代码,供大家参考,具体内容如下

效果:

vue代码统计(Vue实现计数器案例)

  • <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>计数器</title>
        <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
        <style type="text/css">
           #app{
              text-align: center;
              margin: 0 auto;
              line-height: 500px;
           }
    
           #app input{
               width: 50px;
               height: 40px;
               font-size: 20px;
               border-radius: 5px;
               outline: none;
               /* 自定义边框 */
               border: 1px solid transparent;
               background-color: blue;
               line-height: 30px;
               color: white;
           }
           #app span{
               padding: 20px 20px;
               border: 1px;
           }
           
        </style>
    </head>
    <body>
        <li id="app">
          <input type="button" value="-" @click="sub"/>
          <span>{{num}}</span>
          <input type="button" value="+" @click="add"/>
        </li>
    
        <script>
            var app = new Vue({
                el: "#app",
                data: {
                    num: 1
                },
                methods:{
                    add: function(){
                       if(this.num<10){
                        this.num++;
                       }else{
                           alert("达到最大啦!");
                       }                    
                    },
    
                    sub: function(){
                        if(this.num>0){
                            this.num--;
                        }else{
                            alert("已经没有了!");
                        }
                        
                    }
                }
            })
        </script>
    </body>
    </html>
    
  • 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持开心学习网。

    标签:
    上一篇下一篇

    猜您喜欢

    热门推荐