<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Add and Sub</title>
</head>
<body>
<div id="app">
<h1>当前计数为 : {{counter}} </h1>
<!-- <button v-on:click="counter++">add</button>-->
<!-- <button v-on:click="counter--;">sub</button>-->
<button v-on:click="add">add</button>
<button v-on:click="sub">sub</button>
</div>
<script src="../../js/vue.js"></script>
<script>
const app = new Vue({
el : "#app",
data : {
counter : 0
},
// 定义多个方法
methods : {
add : function () {
console.log("add 被执行")
this.counter++
},
sub : function () {
console.log("sub 被执行")
this.counter--
}
}
})
</script>
</body>
</html>