<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id="app">
<h2>{{count}}</h2>
<button @click="add">+</button>
<button @click="sub">-</button>
</div>
<script>
const app = new Vue({
el:"#app",
data:{
count:0
},methods:{
add(){
this.count++
},
sub(){
this.count--
}
}
})
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id="app">
<h2>{{count}}</h2>
<button @click="add">+</button>
<button @click="sub">-</button>
</div>
<script>
const obj = {
count:0
}
const app = new Vue({
el:"#app",
data:obj,
methods:{
add(){
this.count++
},sub(){
this.count--
}
}
})
</script>
</body>
</html>
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者