首页 > 其他分享 >Vue-示例

Vue-示例

时间:2023-03-23 12:46:19浏览次数:34  
标签:function 10 Vue 示例 counter num

计数器

<div id="counter">
    <button @click="subOne">-</button>
    <span>{{num}}</span>
    <button @click="addOne">+</button>
</div>

<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script>
    var counter = new Vue({
        el: '#counter',
        data: {num: 4},
        methods: {
            addOne: function () {
                this.num += 1
                if (this.num > 10) {
                    this.num = 10
                    alert('最大值10')
                }
            },
            subOne: function () {
                this.num -= 1
                if (this.num < 0) {
                    this.num = 0
                    alert('最小值0')
                }
            }
        }
    })
</script>

image

标签:function,10,Vue,示例,counter,num
From: https://www.cnblogs.com/unity-yancy/p/17247041.html

相关文章