computed:屬性不變,使用上一次的計算緩存,性能比較高
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Vue中的计算属性和侦听器</title>
<script src="vue.js"></script>
</head>
<body>
<div id="root"> 姓:
<input v-model="firstName"/>
名:
<input v-model="lastName"/>
<div>{{fullName}} </div>
<div>{{count}}</div>
</div>
<script>
new Vue({
el:"#root",
data:{
firstName:"",
lastName:"",
count:0
},
computed:{
fullName: function (){
return this.firstName+" "+this.lastName;
}
},
watch:{
fullName: function(){
this.count++;
}
}
})
</script>
</body>
</html>