突然翻到很久之前的小练习,备份一下~
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>计数器案例</title>
<style type="text/css">
/*这里写CSS内容*/
.input-num{
margin:0 auto;
background: rgb(223, 231, 231);
width:200px;
height:150px;
border:1px solid rgb(34, 53, 53);
border-radius:30px;
text-align: center;
}
</style>
</head>
<body>
<!-- html结构 -->
<div id="app">
<!-- 计数器功能区-->
<div class="input-num">
<p>简单计数器</p>
<button @click="sub">
-
</button>
<span>{{ num }}</span>
<button @click="add">
+
</button>
</div>
</div>
<!-- 开发环境版本,包含了有帮助的命令行警告 -->
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script>
var app = new Vue({
el: '#app',
data: {
num:1
},
methods:{
add:function(){
if (this.num < 10) {
this.num++;
}else{
alert('死鬼别点了,最大了!');
}
},
sub:function(){
if (this.num > 0) {
this.num--;
}else{
alert('死鬼别点了,最小了!');
}
}
}
})
</script>
</body>
</html>