<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="con">
<h2>当前计数:{{counter}}</h2>
<!-- <button v-on:click="counter--">-</button>
<button v-on:click="counter++">+</button> -->
<!-- <button v-on:click="sub">-</button>
<button v-on:click="add">+</button> -->
<button @click="sub">-</button>
<button @click="add">+</button>
</div>
</body>
<script src="../vue.js"></script>
<script>
const app = new Vue({
el: "#con",
data: {
counter:0
},
methods: {
add: function(){
// app.counter++
this.counter++
},
sub: function(){
// app.counter--
this.counter--
}
}
});
</script>
</html>