<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>
计数器
</title>
</head>
<body>
<div id="app">
<button @click="down">
-
</button>
<span> {{num}}</span>
<button @click="up">
+
</button>
</div>
</body>
<!-- 开发环境版本,包含了有帮助的命令行警告 -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
var app = new Vue({
el:"#app",
data: {
num:1
},
methods: {
up:function(){
if(this.num < 10){
this.num += 1;
}
},
down:function() {
if(this.num > 1){
this.num -= 1;
}
}
}
})
</script>
</html>