var vm=new Vue({
el:'#demo',
data:{
firstName:'Foo',
lastName:"Bar"
// fullName:"Foo Bae"
},
// watch:{
// firstName:function(val){
// this.fullName=val+''+this.lastName
// },
// lastName:function(val){
// this.fullName=this.firstName+''+val
// }
// }
computed:{
// 下面是定义getter函数
fullName:function(){
return this.firstName+' '+this.lastName
}
}
})
<div id="demo">
{{fullName}}
</div>