实现效果

VUE实际案例--计数器(商城数量加减)

 

 

使用时候,自己添加css就好

<div id="app">
    <button v-on:click="subtraction">-</button>
    <span>{{number}}</span>
    <button v-on:click="add">+</button>
</div>


<script src="vue.js"></script>
<script>
    var app = new Vue({
        el:"#app",
        data:{
            number:1
        },
        methods:{
            subtraction:function () {
                if (this.number <= 1){
                    alert("超出范围!")
                }else {
                    this.number -= 1
                }
            },
            add:function () {
                if (this.number >= 5){
                    alert("超出范围!")
                }else {
                    this.number += 1
                }
            },
        }
    })

</script>

 

相关文章:

  • 2022-12-23
  • 2022-02-17
  • 2021-05-07
  • 2021-06-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-02-03
  • 2022-01-18
  • 2022-01-05
  • 2022-12-23
  • 2021-07-25
  • 2021-08-11
相关资源
相似解决方案