1. watch与computed的描述
watch
watch : {
firstName : function(val){
console.log(val);
this.fullName = val + "." + this.lastName;
},
lastName : function(val){
this.fullName = this.firstName + "." + val;
}
},
当fistName变化时,会执行响应的方法。相当于在监听fistName的值
computed
computed : {
c : function(){
return this.b + "." + this.a
}
}
当b或者c变化时,会自动更新c的值,相当于一次监听了a和b的值但是要注意的是,c在data中不能定义。如:
data : {
firstName : "fist",
lastName : "last",
fullName : "fist.last",
a : "1",
b : "2"
},