index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link type="text/css" rel="stylesheet" href="./main.css">
<script src="https://unpkg.com/vue"></script>
<title>Document</title>
</head>
<body>
<!--vue app是根容器-->
<div id="vue-app">
<button @click="a++">++</button>
<button @click="b++">---</button>
<p>a{{a}}</p>
<p>b{{b}}</p>
<p>aga+a{{addToA}}}</p>
<p>age+b{{addToB}}}</p>
</div>
<script src="./app.js"></script>
</body>
</html>
app.js
new Vue({
el:"#vue-app",
data:{
a:0,
b:0,
age:20,
},
computed:{
addToA:function (){
console.log("Add to A")
return this.a+this.age
},
addToB:function (){
console.log("Add to B")
return this.a+this.age
}
},
methods:{
/* updatexy(event){
this.x=event.offsetX,
this.y=event.offsetY
},
stopMoving(event){
event.stopPropagation()
}*/
}
})
运行结果

浙公网安备 33010602011771号