事件绑定

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="js/vue.js"></script>
</head>
<body>
<div id="app">
<button @click="add">+</button>
<input type="text" v-model="num">
<button @click="sub">-</button>
</div>



<script>
var vm = new Vue({
el:"#app",
data:{
num:0,
},
methods:{
add(){
if(this.num>=10) {
this.num = 10
}else{
this.num++
}
},
sub(){
if(this.num<1) {
this.num = 0
}else{
this.num--
}
}


}
});

</script>

</body>
</html>
原文地址:https://www.cnblogs.com/eliwen/p/12029118.html