思路:
<body>
<!-- 计数器0-10 -->
<div id="app">
<div class="input-num">
<button @click="sub">-</button>
<span>{{num}}</span>
<button @click="add">+</button>
</div>
</div>
<script>
/* 生成一个app元素 */
var app = new Vue({
el: "#app",
data: {
num: 1
},
methods: {
sub: function () {
if (this.num > 0) {
this.num--;
} else {
alert("别点啦,下不去了")
}
},
add: function () {
if (this.num < 10) {
this.num++;
} else {
alert("别点啦,太大啦")
}
}
}
})
</script>
</body>