计数器
<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>