computed计算属性

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="vue.js"></script>
</head>
<body>
<div id="vue-app05">
<h1>computed计算属性</h1>
<button v-on:click="a++">Add to A</button>
<button v-on:click="b++">Add to B</button>
<p>A-{{a}}</p>
<p>B-{{b}}</p>
<!-- <p>Age + A = {{addToA()}}</p>
<p>Age + B = {{addToB()}}</p> -->
<p>Age + A = {{addToA}}</p>
<p>Age + B = {{addToB}}</p>
</div>
<script src="computer.js" type="text/javascript" charset="utf-8"></script>
</body>
</html>

new Vue({
el:"#vue-app05",
data:{
a:0,
b:0,
age:20
},
methods:{
// addToA:function(){
// console.log("Add to A")
// return this.a+this.age;
// },
// addToB:function(){
// console.log("Add to B")
// return this.b+this.age;
// },

},
computed:{
addToA:function(){
console.log("Add to A")
return this.a+this.age;
},
addToB:function(){
console.log("Add to B")
return this.b+this.age;
},
}
})

原文地址:https://www.cnblogs.com/weixin2623670713/p/12888370.html